You are viewing a single comment's thread. Return to all comments →
I came up with a similar solution.
Look into Sorting-Algorithms! "Counting Sort" uses a similar idea to this solution. Thats where i got my inspiration from.
The problem (obviously): It only works well if the interval of the countables is comparably "small" to fit into your computers memory.
Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] counting = new int[100]; int a; for(int a_i=0; a_i < n; a_i++){ a = in.nextInt(); if (a==0) { counting[0]++; } else { counting[a]++; counting[a-1]++; } } int max = Integer.MIN_VALUE; for (int i = 0; i < 100; i++) { if (counting[i] > max ) { max = counting[i]; } } System.out.println(max);
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
I came up with a similar solution.
Look into Sorting-Algorithms! "Counting Sort" uses a similar idea to this solution. Thats where i got my inspiration from.
The problem (obviously): It only works well if the interval of the countables is comparably "small" to fit into your computers memory.