Even if I am able to solve a question, I always come back to this channel to verify if I have the solution that is expected in the interview. Many thanks.
An alternate approach to solve the above problem. I treated it like a sweep line. The time complexity is O(nlogn) though. def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]: firstList.extend(secondList) firstList.sort()
answer = [] end = firstList[0][1]
for i in range(1, len(firstList)): if firstList[i][0]
Could work yes, but interviewer will likely for this want O(N) time and without using extra space (from the sort) so expect a follow-up to reduce the complexity of your solution if you do this
@@crackfaang You are correct. I often wonder how to come up with a better solution that is radically different (based on an entirely different idea) than the one you began with. Do you have any pointers when we face the above issue?
@@Shreyas535 Either you are smart enough to come up with it from prior experience with similar algorithms or you just memorise the optimal solution. After you learn the fundamentals of LC and the common algorithms such that you can explain solutions, the rest is just memorisation haha
Bro your explanation is GOLD
Even if I am able to solve a question, I always come back to this channel to verify if I have the solution that is expected in the interview. Many thanks.
Honestly man, I’m sooo grateful for you! Thank you soo much!
we're in the code editor, let's type this up....
An alternate approach to solve the above problem. I treated it like a sweep line. The time complexity is O(nlogn) though.
def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:
firstList.extend(secondList)
firstList.sort()
answer = []
end = firstList[0][1]
for i in range(1, len(firstList)):
if firstList[i][0]
Could work yes, but interviewer will likely for this want O(N) time and without using extra space (from the sort) so expect a follow-up to reduce the complexity of your solution if you do this
@@crackfaang You are correct. I often wonder how to come up with a better solution that is radically different (based on an entirely different idea) than the one you began with. Do you have any pointers when we face the above issue?
@@Shreyas535 Either you are smart enough to come up with it from prior experience with similar algorithms or you just memorise the optimal solution. After you learn the fundamentals of LC and the common algorithms such that you can explain solutions, the rest is just memorisation haha
thank you for making this video
Thank you