Good Solution
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:\n    bool isPossible(vector<int> &nums,vector<int> &changeIndicesZeroBased, int s){\n        int n = nums.size();\n        vector<int> last(n,-1);\n        for(int i=0;i<=s;i++){\n            last[changeIndicesZeroBased[i]]=i;\n        }\n        int completed=0,power=0;\n        for(int i=0;i<=s;i++){\n            if(i==last[changeIndicesZeroBased[i]]){\n                if(nums[changeIndicesZeroBased[i]]>power) return false;\n                power -= nums[changeIndicesZeroBased[i]];\n                completed++;\n            }\n            else{\n                power++;\n            }\n        }\n        return completed==n;\n    }\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        int n=nums.size(),m=changeIndices.size();\n        vector<int> changeIndicesZeroBased=changeIndices;\n        for(auto &el: changeIndicesZeroBased) el--;\n\n        int low=0,high=m-1,ans=-1;\n        while(low<=high){\n            int mid = high + (low-high)/2;\n            if(isPossible(nums,changeIndicesZeroBased,mid)){\n                ans=mid;\n                high=mid-1;\n            }\n            else low=mid+1;\n        }\n        return ans == -1 ? -1 : ans+1;\n    }\n};\n```
['Binary Search', 'C++']