Created
September 26, 2018 03:43
-
-
Save devDeejay/483ec327be429cee92f564f5949662bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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