• + 0 comments

    I implemented algorithm in Java , and after testing , I found that in Test Case 5 , the expected result is 50 , but my actual calculation is 45 , Has anyone encountered this issue?

    I know the issue is on my side , Please , could someone help me check where the problem is in my Code ,

    The following is my code ...

        public static int nonDivisibleSubset(int k, List<Integer> s) {
            s=s.stream().map(item->item%k).collect(Collectors.toList());
            // Write your code here
            s=s.stream().sorted().collect(Collectors.toList());
            int max = 0;
            for (int i = 0; i < s.size(); i++) {
                List<Integer> ans = new ArrayList<>();
                ans.add(s.get(i));
                for (int j = i+1; j < s.size(); j++) {
                    Integer needCheck = s.get(j);
                    boolean match = true;
                    for (Integer an : ans) {
                        if ((an + needCheck) % k == 0) {
                            match = false;
                            break;
                        }
                    }
                    if (match) {
                        ans.add(needCheck);
                    }
                }
                if (max < ans.size()) {
                    max = ans.size();
                }
            }
            return max;
        }