#K40807. Find Target Range in Sorted Array

    ID: 26724 Type: Default 1000ms 256MiB

Find Target Range in Sorted Array

Find Target Range in Sorted Array

Given a sorted array of integers and a target value, find the starting and ending positions of the target value. Your algorithm must run in O(log n) time complexity. If the target is not in the array, output -1 -1.

This problem can be solved using a modified binary search to locate the first and last occurrence of the target.

inputFormat

The input is read from stdin and consists of three parts:

  1. The first line contains an integer n, the number of elements in the array.
  2. The second line contains n space-separated integers representing the sorted array.
  3. The third line contains the target integer.

outputFormat

Output to stdout two space-separated integers. These represent the starting and ending positions of the target in the array. If the target is not found, output -1 -1.

## sample
6
5 7 7 8 8 10
8
3 4

</p>