Easy To Understand C++ Solution ✅✅
Code\n\nclass Solution {\npublic:\n    bool helper(vector<int> &nums,vector<int> &second,int m){\n        int n=nums.size();\n        vector<int> last(n+1,-1);\
# Code\n```\nclass Solution {\npublic:\n    bool helper(vector<int> &nums,vector<int> &second,int m){\n        int n=nums.size();\n        vector<int> last(n+1,-1);\n        for(int i=0;i<m;i++){\n            last[second[i]]=i;\n        }\n        priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;\n        for(int i=0;i<n;i++){\n            if(last[i]==-1){\n                return false;\n            }\n            pq.push({last[i],nums[i]});\n        }\n        int sec_used=0;\n        while(!pq.empty()){\n            int last_sec=pq.top()[0];\n            int val=pq.top()[1];\n            pq.pop();\n            if((last_sec-sec_used)<val){\n                return false;\n            }\n            sec_used+=val+1;\n        }\n        return true;\n    }\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        int n=nums.size();\n        int m=changeIndices.size();\n        for(int i=0;i<m;i++){\n            changeIndices[i]--;\n        }\n        int i=0;\n        int j=m;\n        int ans=-1;\n        while(i<=j){\n            int mid=(j+i)/2;\n            if(helper(nums,changeIndices,mid)){\n                    j=mid-1;\n                    ans=mid;\n            }else{\n                i=mid+1;\n            }\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Heap (Priority Queue)', 'C++']