#C13816. Target Range Finder

    ID: 43396 Type: Default 1000ms 256MiB

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:

  1. An integer \(n\) representing the number of elements in the sorted array.
  2. A line containing \(n\) space-separated integers.
  3. 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.

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