This question evaluates proficiency in array manipulation, duplicate handling, and custom sorting logic with attention to time and space complexity, and it falls within the Coding & Algorithms domain.
You are given an integer array arr of length about 75.
sort()
), and do not call library implementations of quicksort/bubblesort/etc.
If a value appears multiple times, keep exactly one occurrence and replace all other occurrences with 0. Then sort the entire array in non-decreasing order.
arr
.
[3, 1, 3, 2, 2]
[3, 1, 0, 2, 0]
[0, 0, 1, 2, 3]