Google Singapore OA
Summer 2020 Internship
Interview on CoCubes
Previous Question: Greatest Common Divisor
Question #2: https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/
Relative sorting is defined as sorting two arrays (both in strictly ascending order) such that the only operation allowed is swapping i'th element of one array with the i'th elementh of the other array
An array is said to be in strictly ascending order if i'th element of the array is smaller than (i+1)'th element of the array.
You are given two arrays of size N. print the minimum number of swaps required to make both arrays relatively sorted.
The input consist of 3 lines:
The output will be an integer i.e., the minimum number of swaps required to make both arrays relatively sorted.
Example 1:
Input:
4
1 4 4 9
2 3 5 10
Output: 1
Explanation: To make both arrays strictly increasing we can swap 4 and 3 or 4 and 5.