This is a verified interview question from Dp-world. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Outlier Segregation" covers key patterns like Arrays.
"Developers are creating a utility algorithm to segregate outliers in an array. The prototype involves an array arr of n integers, where m elements are non-zero integers, and the remaining n - m elements are zeros. In one operation, the algorithm can swap a zero with a non-zero integer. Task: Determine the minimum number of operations required to: 1. Sort all non-zero elements in ascending order. 2. Move all zeros to the end of the array. ### Example Consider an array arr = [7, 8, 0, 0, 4, 2, 0, 1, 0] of n = 9 integers. An optimal sequence of swaps is shown. Elements to swap are in bold. [7, 8, 0, 0, 4, 2, 0, 1, 0] [7, 8, 0, 0, 4, 2, 0, 1, 0] [0, 8, 4, 7, 2, 0, 1, 0] [0, 0, 4, 7, 8, 2, 0, 1, 0] [0, 0, 4, 7, 8, 2, 0, 1, 0] [0, 2, 4, 7, 8, 0, 0, 1, 0] [1, 2, 4, 7, 8, 0, 0, 0, 0] Return 5, the minimum number of operations required."
Join thousands of developers practicing for Dp-world.