CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsBinary Search

Find First and Last Position

Medium
LeetCode
3/3
MediumBinary SearchLeetCode #34

First & Last Position

Two binary searches: leftmost and rightmost index of target.

Examples

Example 1

Input

6 8
5 7 7 8 8 10

Output

3 4
Example 2

Input

6 6
5 7 7 8 8 10

Output

-1 -1

Stuck? Take a nudge

C++17Autosaves