Codewars Brush question fifth day, array problem.
Enough is enough!
Alice and Bob were on a holiday. Both of them took many pictures of the places they ' ve been,
And now they want to show Charlie their entire collection.
However, Charlie doesn ' t like this sessions, since the motive usually repeats.
He isn ' t fond of seeing the Eiffel tower.
He tells them that he'll only sit during the session if they show the same motive at most N times.
Luckily, Alice and Bob is able to encode the motive as a number.
Can them to remove numbers such this their list contains each number is only up to N times,
Without changing the order?
Task
Given a list lst and a number N,
Create a new list that contains each number of the LST at the most N times without reordering.
For example if N = 2, and the input is [1,2,3,1,2,1,2,3],
You take [1,2,3,1,2], drop the next [up] since this would leads to 1 and 2 being in the result 3 times,
And then take 3, which leads to [1,2,3,1,2,3].
Example
Enoughisenough.deletenth (new int[] {20,37,20,21}, 1)//return [20,37,21]
Enoughisenough.deletenth (new int[] {1,1,3,3,7,2,2,2,2}, 3)//return [1, 1, 3, 3, 7, 2, 2, 2]
Title Requirements:
Given an array, the number of occurrences in the array must not exceed the limit given the limit maxoccurrences. The array is then returned,
For this indeterminate length problem, it is recommended to use a vector (), or a hash table.
Here, two functions are used to compare ingenious Getordefault (int,int) and Arrays.copyofrange (int,int,int). It's a good solution to the problem in traversal.
Java Brush Question (v)