INTERVAL LIST INTERSECTIONS | LEETCODE 986 | PYTHON TWO-POINTER SOLUTION

Поділитися
Вставка
  • Опубліковано 7 січ 2025

КОМЕНТАРІ • 10

  • @chisomedoka5651
    @chisomedoka5651 9 місяців тому +5

    Bro your explanation is GOLD

  • @Igloo683
    @Igloo683 Місяць тому

    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.

  • @dnm9931
    @dnm9931 6 місяців тому +1

    Honestly man, I’m sooo grateful for you! Thank you soo much!

  • @olajideogundipejr6021
    @olajideogundipejr6021 7 місяців тому +3

    we're in the code editor, let's type this up....

  • @Shreyas535
    @Shreyas535 11 місяців тому

    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]

    • @crackfaang
      @crackfaang  11 місяців тому

      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

    • @Shreyas535
      @Shreyas535 11 місяців тому

      @@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?

    • @crackfaang
      @crackfaang  11 місяців тому +6

      @@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

  • @rostislav_engineer
    @rostislav_engineer 8 місяців тому

    thank you for making this video

  • @sarayarmohammadi3376
    @sarayarmohammadi3376 2 місяці тому

    Thank you