Loading...
Loading...
Loading...
A shop's billing list has item codes. An item has been recalled, so every entry with code x must be removed. Build a new array without x, keeping the other codes in their order.
EMPTY on the second line.Example 1
Input
7 5 3 5 8 1 5 2 5
Output
4 3 8 1 2
The three 5s are removed.
Example 2
Input
3 4 4 4 4
Output
0 EMPTY
Every code was x.
Try the problem first. Open one hint at a time.
An array cannot shrink. First count how many codes are not x, then create a new array of exactly that size.
Copy the other codes using a separate index k for the new array.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor