Answer: DISPRZ Hiring Challenge | On-Campus OA (2024) | Minimum Number of Moves
Answer · Posted Jun 2026
Approach Sort both arrays. Pair the smallest seat with the smallest student. Sum the absolute differences between corresponding positions. Sorting guarantees the minimum total movement. Java Solution import java.util.Arrays; class Solution { public int minMovesToSeat(int[] seats, int[] students) { Arrays.sort(seats); Arrays.sort(students); int totalMoves = 0; for (int i = 0; i < seats.length; i++) { totalMoves += Math.abs(seats[i] - students[i]); } return totalMoves; } } Time Complexity O(n log n) Space Complexity O(1)
The full answer & interview discussion are available to premium members.
Log in Create a free account