99% beats Beginner friendly
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    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& c) \n    {\n        \n        int m = c.size();\n        int left =0,right = m,fina=-1;\n        int n = nums.size();\n        vector<int>temp=nums;\n        while(left<=right)\n        {\n            int mid = (left+right)/2;\n            if(mid < n)\n            {\n                left = mid+1;\n                continue;\n            }\n            int ans = mid;\n            bool p = true;\n            int cnt=0;\n            for(int i=mid;i>0;i--)\n            {\n\n                if(nums[c[i-1]-1]== -1)\n                {\n                    if(cnt>0)\n                    cnt--;\n                    \n                    continue;  \n                }\n               \n                 else\n                 {\n                     if(i-1-cnt>=nums[c[i-1]-1])\n                     {\n                     ans -= (nums[c[i-1]-1]+1);\n                     cnt+= nums[c[i-1]-1];\n                      nums[c[i-1]-1]=-1;\n                     }\n                     else\n                     {\n                         p=false;\n                         goto skip;\n                     }\n                //     if(mid==18)\n                //   cout<<i<<\' \'<<ans<<endl;\n                 } \n                //  else\n                //  goto skip;\n              \n            }\n            // if(mid==18)\n            //  cout<<ans;\n            if(ans<0)\n            {\n                p = false;\n                goto skip;\n            }\n            for(int i=0;i<n;i++)\n            {\n                if(nums[i]!=-1)\n                {\n                     p = false;\n                     goto skip;\n                }\n            }\n           \n           skip:\n            if(p)\n            {\n                fina = mid;\n                 right = mid-1;\n            }\n            else\n            {\n                left = mid+1;\n               \n            }\n            nums=temp;\n        }\n        return fina;\n        \n    }\n};\n```
['C++']