easy solution using hashmap and sorting.
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```\n#define ll long long \nclass Solution {\npublic:\n    bool solve(vector<int>& nums,map<int,int> &m){\n        vector<pair<int,int>> v;\n        for(auto a:m){\n            v.push_back({a.second,a.first});\n        }\n        sort(v.begin(),v.end());\n        int prev=1;\n        int k=0;\n        for(int i=0;i<v.size();i++){\n            \n            k+=v[i].first-prev;\n            if(k>=nums[v[i].second-1]){\n                k-=nums[v[i].second-1];\n                prev=v[i].first+1;\n            }\n            else return false;\n\n        }\n        return true;\n    }\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& change) {\n        int n=nums.size();\n        \n        int ans=0;\n        bool flag =false;\n        map<int,int> m;\n        for(int i=0;i<change.size();i++){\n            m[change[i]]=i+1;\n            if(m.size()==n){\n               \n                flag=flag || solve(nums,m);\n                if(flag){\n                    ans=i+1;\n                    break;\n                }\n            }\n        }\n        \n        return flag?ans:-1;\n    }\n};\n```
['C++']