← Back to Arrays
Question 121
Remove Duplicates and Print
Remove Duplicates and Print
An array called nums has already been created for you with the values {10, 20, 10, 30, 20}.
Your task is to print only the unique values: the first time each number appears. If a number has already appeared earlier in the array, skip it.
For each element, you need to check whether it appeared at any earlier index. If it did, don't print it. If it didn't, print it.
In this array:
- 10 at index 0: first time → print
- 20 at index 1: first time → print
- 10 at index 2: already appeared at index 0 → skip
- 30 at index 3: first time → print
- 20 at index 4: already appeared at index 1 → skip
Print the unique values on one line separated by spaces.
Expected output:
10 20 30 Expected Output:
10 20 30
Topics:
Arrays
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.