Tricky ??? Not Really !!!
Intuition and Approach\n(1-based indexing)\n1) Try every second starting from s=1 to s=m\n2) How to check for a particular s if it possible to mark all indices 
# Intuition and Approach\n(1-based indexing)\n1) Try every second starting from s=1 to s=m\n2) How to check for a particular s if it possible to mark all indices till s ?\n- If we want to mark some index i, try to mark it as last as possible so that if there is some \nbottleneck index whose has to decrease and get marked earlier possibly because it has only few chances to get marked and also these chances are earlier in time. So, we don\'t want to unnecessarily hinder\nother markings.\n- Now, what do we need to know to mark some index i\' at second s\' (s\'<=s) , there must be atleast nums[i]\nempty seconds to decrese the value at index i\' before s\'.\n- Let s1,s2,s3,..,sn be the last seconds where index 1,2,3...,n can be marked (si<=s for all i) \n- We want to process there in sorted order (example : s=5,n=2, s1=4,s2=2, since s2 has bottleneck to be marked earlier so we will process s2 then s1)\n- Now, for every i, there must be nums[i] empty seconds to decrese the value before si and si will be there to mark i. While processing , we need to keep track of how to second are already consumed by other si\'s combinedly in decreasing marking \n\nNow, optimise the 1) by thinking like this \nCan we do it in s second ? FFFFFTTTTT or TTTTTTTT or FFFFFFFFF\nFind first s whose value is True (binary search)\n\n# Complexity\n- Time complexity: O((m+n)logm)\n\n- Space complexity: O(n) space is used in every possible() call.\n\n# Code\n```\nclass Solution {\npublic:\n\n    bool possible(int s,vector<int>& nums,vector<int>& changeIndices){\n        // cout<<"####"<<s<<"####\\n";\n        int n = nums.size();\n        int m = changeIndices.size();\n        //find last occurances of all indices of n\n        unordered_set<int> last_occurance_set;\n        vector<int> last_occurance(n,-1); // last occurances second \n        for(int i=0;i<s;i++){\n            last_occurance[changeIndices[i]-1] = max(last_occurance[changeIndices[i]-1],i+1);\n        }\n\n        for(int i=0;i<n;i++){\n            if(last_occurance[i]==-1)return false; //all indices don\'t appear in changeIndices till s\n            last_occurance_set.insert(last_occurance[i]);\n            cout<<last_occurance[i]<<endl;\n        }\n\n        int empty_slots=0;\n        for(int i=0;i<s;i++){\n            int second = i+1;\n            if(last_occurance_set.find(second)==last_occurance_set.end()){\n                empty_slots++;\n                continue;\n            }\n            else{\n                if(nums[changeIndices[i]-1]>empty_slots)return false;//not enough empty slots\n                empty_slots-=nums[changeIndices[i]-1];\n            }\n        }\n\n        return true;\n    }\n\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n\n        int n = nums.size();\n        int m = changeIndices.size();\n        int start = 1;\n        int end = m;\n        int mid = (start+end)/2;\n        while(end-start>1){\n            mid = (start+end)/2;\n            //FFFFFTTTT\n            if(possible(mid,nums,changeIndices)==true){\n                end=mid;\n            }\n            else{\n                start=mid+1;\n            }\n        }\n\n        if(possible(start,nums,changeIndices)==true)\n            return start;\n        if(possible(mid,nums,changeIndices)==true)\n            return mid;\n        if(possible(end,nums,changeIndices)==true)\n            return end;\n        return -1;\n    }\n};\n```
['Binary Search', 'C++']