Problem Β· Greedy

Meetup Schedule πŸ“†

Learn this problem
● MediumWerideINTERNOA

Problem statement

A start-up owner is looking to meet new investors to get some funds for his company. Each investor has a tight schedule that the owner has to respect. Given the schedules of the days investors are available, determine how many meetings the owner can schedule. Note that the owner can only have one meeting per day.

The schedules consists of two integer arrays, firstDay and lastDay. Each element in the array firstDay represents the first day an investor is available, and each element in lastDay represents the last day an investor is available, both inclusive.

Function

maxMeetings(firstDay: int[], lastDay: int[]) β†’ int

Complete the function maxMeetings in the editor.

maxMeetings has the following parameters:

  1. int[] firstDay: an array of integers representing the first day investors are available
  2. int[] lastDay: an array of integers representing the last day investors are available

Returns

int: the maximum number of meetings that can be scheduled

Examples

Example 1

firstDay = [1, 2, 3, 3, 3]lastDay = [2, 3, 4, 4, 4]return = 4
There are 5 investors [0-1, 1-2, 1-3, 1-4] etc.
  • The investor I-0 is available from day 1 to day 2 inclusive [1, 2].
  • The investor I-1 is available in day 2 only [2, 2].
  • The investor I-2 is available in day 3 only [3, 3].
  • The investors I-3 and I-4 are available from day 3 to day 4 only [3, 4].
  • The owner can only meet 4 investors out of 5: I-0 in day 1, I-1 in day 2, I-2 in day 3, and I-3 in day 4. The graphic below shows the scheduled meetings in green and blocked days are in gray.

    Constraints

    Unkown for now. Will be sure to add once find them

    More Weride problems

    drafts saved locally
    public int maxMeetings(int[] firstDay, int[] lastDay) {
        // write your code here
    }
    
    firstDay[1, 2, 3, 3, 3]
    lastDay[2, 3, 4, 4, 4]
    expected4
    checking account