Hair salon
Statement
N people want a haircut at the salon. Assume each of the N people made a booking measured in seconds. The haircut time each person booked is written as a start time (start) and an end time (end). As an array this is [start, end], a 1D array with two elements. A day is 86,400 seconds, so start is given as an integer from 0 to 86,399.
A hairdresser also cannot cut more than one customer's hair at a time. For example, with one customer booked for [3000, 6000] and another for [4000, 7000], taking both is impossible. Assume that the time a customer takes to enter the salon and the waiting time are both 0 seconds. Write a program that computes the largest number of customers one hairdresser can take.
For example, suppose N=5 customers want a haircut. In this example the haircut times they booked are [3, 7], [4, 8], [1, 2], [7, 10], [4, 7]. Here the largest number of bookings one hairdresser can take is 3.
> (The figure showing the booking intervals was lost when the text was extracted from the original document.)
Input and Output Examples
Example 1
Input
5, [[3, 7], [4, 8], [1, 2], [7, 10], [4, 7]]
Output
3
Example 2
Input
8, [[2, 7], [7, 10], [10, 13], [10, 12], [12, 15], [15, 16], [15, 18], [16, 17]]
Output
6
Input
First the number of bookings N is given as a natural number. (N is a natural number of at most 100,000.)
Next comes reserved, an array holding the haircut time each person wants. The array is a 2D array with N rows and 2 columns. The booked time for each customer is given as [start, end]. For each customer start is an integer from 0 to 86,399, and end is an integer from start+1 to 86,400.
Output
Return the largest number of customers one hairdresser can take.
Requirements
- You must write a solution(N, reserved) function and return the answer
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 20 cases, and 2 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 20 cases to solve this.
Examples
2 public cases. Judging also uses hidden cases. You have to pass all 20 cases to solve this.
5, [[3, 7], [4, 8], [1, 2], [7, 10], [4, 7]]
3
8, [[2, 7], [7, 10], [10, 13], [10, 12], [12, 15], [15, 16], [15, 18], [16, 17]]
6
Notes
Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.
This is problem 1 of practice test 4 in the original.
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 2 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Input read time 335ms (excluded from the ranking)
This person kept their code private.
Input read time 641ms (excluded from the ranking)
Log in and you can see the code once you solve this problem.