<p>Given an array of integers <code>nums</code> sorted in non-decreasing order, find the starting and ending position of a given <code>target</code> value.</p>

<p>If <code>target</code> is not found in the array, return <code>[-1, -1]</code>.</p>

<p>You must&nbsp;write an algorithm with&nbsp;<code>O(log n)</code> runtime complexity.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [5,7,7,8,8,10], target = 8
<strong>Output:</strong> [3,4]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [5,7,7,8,8,10], target = 6
<strong>Output:</strong> [-1,-1]
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> nums = [], target = 0
<strong>Output:</strong> [-1,-1]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>9</sup>&nbsp;&lt;= nums[i]&nbsp;&lt;= 10<sup>9</sup></code></li>
	<li><code>nums</code> is a non-decreasing array.</li>
	<li><code>-10<sup>9</sup>&nbsp;&lt;= target&nbsp;&lt;= 10<sup>9</sup></code></li>
</ul>

class Solution {
    int binf(vector<int> &arr, int target){
        if(arr[0]==target) return 0;
        int k = arr.size()-1;
        int idx = 0;
        while(k>0){
            cout<<k<<endl;
            if(idx+k<arr.size() && arr[idx + k]<target) idx+=k;
            int t = (k%2!=0);
            k/=2;
            if(k!=0) k+=t;
        }
        if(idx+1<arr.size() && arr[idx+1]==target)return idx+1;
        return -1;
    }

    int binl(vector<int> &arr, int target){
        if(arr[arr.size()-1]==target) return arr.size()-1;
        int k = arr.size()-1;
        int idx = 0;
        while(k>0){
            if(idx+k<arr.size() && arr[idx + k]<=target) idx+=k;
            int t = (k%2!=0);
            k/=2;
            if(k!=0) k+=t;
        }
        if(idx<arr.size() && arr[idx]==target)return idx;
        return -1;
    }
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if(nums.size()==0) return {-1,-1};
        return {binf(nums,target),binl(nums,target)};
    }
};
15900