Relative Sort (Google Singapore)
Problem Overview
- Task: Given two arrays of size N, find the minimum number of index-aligned swaps (swap A[i] with B[i]) to make both arrays strictly ascending.
- Input/Output: Read N and two arrays; output an integer: minimum swaps, 0 if already sorted, or -1 if impossible.
- Constraints: 0 < N < 11000; elements are 1 to 1e9; both arrays must end strictly increasing.
- Context: Models pairwise data alignment where only position-wise exchanges are allowed.
- Source: Google Singapore coding interview; common interview question/problem.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
