c++ | binary search | explained
\nclass Solution {\npublic:\n    bool check(int idx, vector<int> &arr, vector<int> &v) {\n        unordered_map<int, int> mpp;\n        long long int sm = 0;\n 
```\nclass Solution {\npublic:\n    bool check(int idx, vector<int> &arr, vector<int> &v) {\n        unordered_map<int, int> mpp;\n        long long int sm = 0;\n        for(int i=(idx); i>=0; i--) {\n            int arri = v[i]-1;\n            if(mpp[arri] == 0) {\n                sm += arr[arri] * 1LL;\n                mpp[arri] = 1;\n            } else {\n                sm = max(0LL, sm - 1LL);\n            }\n        } \n        \n        if(mpp.size() == arr.size() and sm == 0) {\n            return true;\n        }\n        return false;\n    }\n    \n    int earliestSecondToMarkIndices(vector<int>& arr, vector<int>& v) {\n        int m = v.size();\n        int hi = m;\n        int lo = 0;\n        \n        while(lo < hi) {\n            int m = (lo+hi)/2;\n            \n            if(check(m, arr, v) == true) {\n                hi = m;\n            } else {\n                lo = m+1;\n            }\n            \n        }\n        \n        if(hi == m) {\n            return -1;\n        }\n        return hi+1;\n    }\n};\n```\n\n\n1) The last occorance of index in indices list should have the arr[index] as zero. So if dont have it zero by now then even if is zero by randomly chosing that index, but we will never be able to mark that index.\n2) Let me explain the IF condition - We know we at least to sum all the arrary values to make all zero. This is the amount we need to subtract and we need to compare it with seconds. \n3) If we have  a large time T then we can reduce all to zero and and do nothing for rest of the time. \n4) [0......T] the last occurance of an index should be the point where we need to mark the index(not necessarily but a good place to start thinkng).\n5) We should sum all the values of unique element values and rest elements will be used to decrement that value, so that it becomes negetive or zero. \n\n\n
['C', 'Binary Tree']