Created
April 8, 2022 10:52
-
-
Save thekhairul/c07763a3b76465a137bd81808d289d12 to your computer and use it in GitHub Desktop.
InterviewBit - hotel booking possible or not with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hotel(self, arrive, depart, K): | |
arrive.sort() | |
depart.sort() | |
n = len(arrive) | |
i,j = 0,0 | |
booked = 0 | |
while i < n and j < n: | |
if arrive[i] < depart[j]: | |
booked += 1 | |
i += 1 | |
if booked > K: | |
return False | |
elif depart[j] < arrive[i]: | |
booked -= 1 | |
j += 1 | |
else: | |
i += 1 | |
j += 1 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment