Given a sorted array of integers, find the starting and ending position of a given target value.

Your algorithm's runtime complexity must be in the order of O(log n).

If the target is not found in the array, return [-1, -1].

For example,

Given [5, 7, 7, 8, 8, 10] and target value 8,

return [3, 4].

`````` 1 class Solution
2 {
3 public:
4     vector<int> searchRange(int A[], int n, int target)
5     {
6         int l1 = 0, r1 = n - 1, m1;
7         while(l1 <= r1)
8         {
9             m1 = (l1 + r1) / 2;
10             if(target <= A[m1])
11                 r1 = m1 - 1;
12             else
13                 l1 = m1 + 1;
14         }
15
16         int l2 = 0, r2 = n - 1, m2;
17         while(l2 <= r2)
18         {
19             m2 = (l2 + r2) / 2;
20             if(target >= A[m2])
21                 l2 = m2 + 1;
22             else
23                 r2 = m2 - 1;
24         }
25
26         if(l1 <= r2)
27             return vector<int>{l1, r2};
28         else
29             return vector<int>{-1, -1};
30     }
31 };``````