Skip to content

Instantly share code, notes, and snippets.

@thekhairul
Created April 8, 2022 10:52
Show Gist options
  • Save thekhairul/c07763a3b76465a137bd81808d289d12 to your computer and use it in GitHub Desktop.
Save thekhairul/c07763a3b76465a137bd81808d289d12 to your computer and use it in GitHub Desktop.
InterviewBit - hotel booking possible or not with python
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