Minimum days to complete work

We have to complete a total of ‘N’ works. Now, each work can be done on only one of the two special days given in 2 different arrays ‘day1’ and ‘day2’ respectively.

day1[i] denotes that the ‘i-th’ work can on the day1[i] th day and day2[i] denotes that the ‘i-th’ work can on the day2[i] th day. Also, it is guaranteed that day2[i] < day1[i].

Also, make sure, the works are being done in such a way that they must be in non-decreasing order in terms of days given in array ‘day1’.

Your task is to find the minimum number of days in which all the work can be completed.

For example
day1 = {5, 6, 2}
day2 = {2, 4, 1}

In this case, the ideal order will be to perform work 3 on the first day, work 1 on the second day and work 2 on the fourth day. The order with respect to Day1 in which the work is done will be {2, 5, 6} which is non-decreasing. Hence the number of days needed to finish all work will be 4.
Input format :
The first line of input contains an integer ‘T’ denoting the number of test cases.

The next ‘3 * T’ lines represent the ‘T’ test cases.

The First line of each test case contains a single integer ‘N’ denoting the number of works to be done.

The second line contains ‘N’ space-separated integers denoting the sequence day1.

The last line contains ‘N’ space-separated integers denoting the sequence day2.
Output format :
For each test case, return the minimum number of days required to complete the work.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given functions.
Constraints:
1 <= T <= 50
0 <= N <= 10^3
1<= day1[i],day2[i] <= 10^9

Time Limit: 1 sec
CodingNinjas
author
2y

It is a simple iteration problem.

CodingNinjas
author
2y
Greedy Approach
  • Since it is guaranteed that day2[i] < day1[i] and also we need to ensure that the order in which the work is done is non decreasing in terms of day1[i], we can pair up each work and sor...read more
Help your peers!
Add answer anonymously...
Optum Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter