Skip to content

Instantly share code, notes, and snippets.

@devDeejay
Created September 26, 2018 03:43
Show Gist options
  • Select an option

  • Save devDeejay/483ec327be429cee92f564f5949662bb to your computer and use it in GitHub Desktop.

Select an option

Save devDeejay/483ec327be429cee92f564f5949662bb to your computer and use it in GitHub Desktop.
import java.util.*;
public class test {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int count = 0;
Scanner in = new Scanner(System.in);
ArrayList list = new ArrayList();
int n = in.nextInt();
int m = in.nextInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = in.nextInt();
}
for (int i = 0; i <= n - m; i++) {
int currentCount = 0;
for (int j = i; j < (i + m); j++) {
if (list.contains(array[j])) {
currentCount++;
} else {
list.add(array[j]);
}
}
if ((m - currentCount) > count) {
count = (m - currentCount);
}
list.clear();
}
System.out.println(count);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/1000 + " seconds");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment