Rearrange the readings so all dead sensors (zeros) are pushed to the end, preserving the order of valid readings.
Explanation: Step-by-step: Given input [7, 11, 4, 0, 0, 0], we first separate the valid readings (7, 11, 4) from the dead sensors (0, 0, 0). Then we preserve the order of valid readings by keeping them in the same order and appending the dead sensors at the end, resulting in output [7, 11, 4, 0, 0, 0].
Explanation: Step-by-step: Given input [1, 2, 3, 0, 0, 0], we first separate the valid readings (1, 2, 3) from the dead sensors (0, 0, 0). Then we preserve the order of valid readings by keeping them in the same order and appending the dead sensors at the end, resulting in output [1, 2, 3, 0, 0, 0].
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak