Easy Binary Search
Code\n\nclass Solution {\npublic:\n    bool isPossible(int t, vector<int>& changeIndices, vector<int>& nums)\n    {\n        vector<int> lastIndex(nums.size(),-
# Code\n```\nclass Solution {\npublic:\n    bool isPossible(int t, vector<int>& changeIndices, vector<int>& nums)\n    {\n        vector<int> lastIndex(nums.size(),-1);\n        for(int i=0;i<=t-1;i++)\n        {\n            lastIndex[changeIndices[i]-1]=i;\n        }\n        for(int i=0;i<lastIndex.size();i++) \n        {\n            if(lastIndex[i]==-1) return false;\n        }\n        int operations=0;\n        for(int i=0;i<=t-1;i++)\n        {\n            if(lastIndex[changeIndices[i]-1]==i)\n            {\n                if(nums[changeIndices[i]-1]>operations) return false;\n                else operations-=nums[changeIndices[i]-1];\n            }\n            else operations++;\n        }\n        return true;\n    }\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        int start=1;\n        int end=changeIndices.size();\n        int ans=-1;\n        while(start<=end)\n        {\n            int mid=start+(end-start)/2;\n            if(isPossible(mid,changeIndices,nums))\n            {\n                ans=mid;\n                end=mid-1;\n            }\n            else start=mid+1;\n        }\n        return (ans==-1?-1:ans);\n    }\n};\n```
['Binary Search', 'C++']