#BS0000003. Vị trí đầu và cuối của phần tử (Find First and Last Position)
Vị trí đầu và cuối của phần tử (Find First and Last Position)
Find First and Last Position of Element in Sorted Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers sorted in non-decreasing order and target, find its first and last positions. If absent, print -1 -1. Indices start at . Required time: .
Input
The first line contains and target. The second line contains non-decreasing integers; it may be empty when .
Output
Print first last, or -1 -1 if target is absent.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: , .
Examples
Input
6 8
5 7 7 8 8 10
Output
3 4
Explanation
8 occurs from index through index , so the result is 3 4.