You are viewing a single comment's thread. Return to all comments →
public class UniqueIntegers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); Set<Integer> set = new HashSet<>(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scanner.nextInt(); } int maxUnique = 0; for (int i = 0; i <= n - k; i++) { set.clear(); for (int j = i; j < i + k; j++) { set.add(arr[j]); } maxUnique = Math.max(maxUnique, set.size()); } System.out.println(maxUnique); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Dequeue
You are viewing a single comment's thread. Return to all comments →