USING BINARY SEARCH || FOR ITERATION || 33ms Beats 70% || with comments
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nbool markingAllindices(int n, int seconds,vector<int>& nums,vector<int>& changeIndices)\n{\n    vector<int>indices(n+1, -1);//making a array of n+1 size because of 1 based indexing\n\n    for(int i = 0; i <= seconds; i++) // marking the last position of the value\n        indices[changeIndices[i]] = i+1;\n\n    for(int i = 1; i <= n; i++) // checking the condition if anyone is marked -1 afer 1 that means all the indices are not marked \n       if(indices[i] == -1)\n        return false;\n\n    map<int,int>mp; // map is taken instead of unorderd_map because of i have to sort the pair in accordance of the last occuraces of the index\n     //  pair<int,int> -> last occurances and second is the index \n\n    for(int i = 1; i <= n; i++) // pushing it in the map\n        mp[indices[i]] = i;\n\n    \n    int timerequired = 0; // here i have just have logic to mark all the index in minimum time if it is possible\n\n    //   if the reuired time is greater then the last position the  it is inpossible to mark all the element \n\n\n    for(auto i : mp)\n    {\n        int time = nums[i.second - 1] + 1;\n\n        if(time + timerequired > i.first)\n          return false;\n        timerequired += time;\n    }\n /// if all the indeces are marked then return true;\n    return true;\n}\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        int n = nums.size(); \n        int m = changeIndices.size();\n\n        // for(int i = 0; i < m; i++)\n        // {\n        //     if(markingAllindices(n,i,nums,changeIndices))//iterating all the indices till where it will mark all the indices\n        //      return i+1;// if all the indices are marked just return time because it i s 1 based indexing\n        // }\n\n\n        // using binary search to get the earlier\n\n        int left = 0;\n        int right = m-1;\n\n        int ans = -1;\n\n        while(left <= right)\n        {\n            int mid = left + (right - left)/2;\n            if(markingAllindices(n,mid,nums,changeIndices))\n            {\n                 ans = mid+1;\n                 right = mid - 1;\n            }\n            else \n            {\n                left = mid + 1;\n            }\n\n        }\n        return ans;\n    }\n};\n```
['C++']