binary search+Greedy brainteasing but easy 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\nbool bsearch(vector<int>& nums, vector<int>& ind,int n){\n    unordered_map<int,int>lastOccu;\n    for(int i=0;i<n;i++){\n        lastOccu[ind[i]]=i;\n    }\n    if(lastOccu.size()!=nums.size()){\n        return false;\n    }\n    int c=0;\n    for(int i=0;i<n;i++){\n        if(i==lastOccu[ind[i]]){\n            if(c<nums[ind[i]-1]){\n                return false;\n            }\n            else{\n                c-=nums[ind[i]-1];\n            }\n        }\n        else{\n            c++;\n        }\n    }\n    return true;\n}\n\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& ind) {\n        int i=0;\n        int n=ind.size();\n        int j=n+1;\n\n        while(i<j){\n            int mid=i+(j-i)/2;\n            if(bsearch(nums,ind,mid)){\n                j=mid;\n            }\n            else{\n                i=mid+1;\n            }\n        }\n\n        if(j==n+1){\n            return -1;\n        }\n        else{\n            return j;\n        }\n    }\n};\n```
['Binary Search', 'Greedy', 'C++']