Minimum Days to Complete Work

You have 'N' tasks to complete. Each task can only be done on one of two specific days provided in two arrays: day1 and day2.

For each task i, day1[i] represents the earliest day task i can be done on array day1 and day2[i] represents the earliest day task i can be done on array day2. It is guaranteed that day2[i] < day1[i].

The tasks must be scheduled such that the completion days are in non-decreasing order from day1, and you need to determine the minimum number of days required to complete all tasks.

Example:

Input:
day1 = [5, 6, 2]  
day2 = [2, 4, 1]
Output:
4
Explanation:

Complete work 3 on day 1, work 1 on day 2, and work 2 on day 4. The completion order with respect to day1 is [2, 5, 6], which is non-decreasing, so the number of days required is 4.

Constraints:

  • 1 <= T <= 50
  • 0 <= N <= 10^3
  • 1 <= day1[i], day2[i] <= 10^9
  • Time Limit: 1 sec
Be the first one to answer
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

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