3 (4?) lines Python, beats 95%


  • 0
    2

    However, I'm not clear about what it needs to be when there's conflicts.

    Say [ (2, 3), (3, 5), (3, 4) ].

    def findRightInterval(self, intervals):
    start_index = {interval.start: index for index, interval in enumerate(intervals)}
    right_index = [start_index[interval.end] if interval.end in start_index else -1
    for index, interval in enumerate(intervals)]
    return right_index


  • 0
    D

    It states in the problem that no two intervals share a start.


  • 1
    D

    This solution does not give the correct solution for the input
    [[1,2], [3,4]]

    What you do is only check if the end point of the interval is a start point of another interval but the question is asking for the first interval in which the start point is to the greater than or equal to the current intervals end point.


  • 0

    @Diddi That test case (and maybe a larger random one) should be added. @1337c0d3r


  • 0
    2

    @Diddi You're correct. I will think more about it.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.