#C13816. Target Range Finder
Target Range Finder
Target Range Finder
You are given a sorted array of integers and a target value. Your task is to find the starting and ending positions of the target value in the array. If the target is not present, output -1 -1
.
The solution must have a time complexity of \(O(\log n)\) by using a binary search based technique.
Example:
- Input: 6
Array: [5, 7, 7, 8, 8, 10]
Target: 8
Output: 3 4 - Input: 6
Array: [5, 7, 7, 8, 8, 10]
Target: 6
Output: -1 -1
inputFormat
The input is given via standard input (stdin) in the following format:
- An integer \(n\) representing the number of elements in the sorted array.
- A line containing \(n\) space-separated integers.
- An integer representing the target value.
outputFormat
Output the starting and ending positions of the target value separated by a space to standard output (stdout). If the target is not found, output -1 -1
.
6
5 7 7 8 8 10
8
3 4