Search for a Range


  • 0

    Click here to see the full article post


  • 0
    R

    Not sure if the solution 2 works with the test case [1, 2, 5, 5, 5] with target 5.


  • 0

    @ruiixu23 Both the Java and Python3 solutions return [2,4], so they seem correct to me. Next time, you can check this yourself by pasting the editorial solutions into the submission box and using the "Custom Testcase" option.


  • 0
    R

    Sorry. Overlooked that you set (line 6 of Java code) hi to nums.length, which doesn't correspond to what the animation is showing. I was assuming using nums.length - 1 to initialize hi. In that case, it will be wrong and I hope you agree with me.


  • 0

    @ruiixu23 Ah, fair enough. I can see how that might be a tad confusing; exclusive vs. inclusive ends of ranges. :) I apologize for snapping at you.


  • 0
    H

    STL comes to rescue here, Use C++ inbuilt function equal_range().
    One line of code :)


  • 0
    B

    Why is Linear Scan accepted if it has a runtime complexity of O(n)?


  • 0
    C

    What's the point of giving Approach #1......


  • 0
    E

    The 1st approach should not be there at all ..... question clearly asks for O(log n ) time, your interview fails at the moment you try to do this in linear !

    2nd Approach is not straightforward enough for me.


Log in to reply
 

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