🔥BinarySearch on ANS⚡ || ✅Clean Code💯
\n\n# Complexity\n\n- Time complexity:\nO(n * log n * log m)\n\n- Space complexity:\nO(n)\n\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n\nclass Solutio
\n\n# Complexity\n```\n- Time complexity:\nO(n * log n * log m)\n\n- Space complexity:\nO(n)\n```\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n    int n, m;\n    bool feasible(int time, vector<int>& nums, vector<int>& ci){\n        if(time < n)\n            return false;\n        vector<int> lastOcc(n, -1);\n        for(int i = 0 ; i < time ; i++)\n            lastOcc[ci[i] - 1] = i;\n        vector<pair<int ,int>> p;\n        for(int i = 0 ; i < n ; i++){\n            if(lastOcc[i] == -1)\n                return false;\n            p.push_back({lastOcc[i] + 1, i + 1});\n        }\n        sort(p.begin(), p.end());\n        int req_time = 0;\n        for(auto [lastInd, ind] : p){\n            req_time += nums[ind - 1] + 1;\n            if(req_time > lastInd)\n                return false;\n        }\n        return true;\n    }\n    \n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& ci) {\n        n = nums.size(), m = ci.size();\n        int ll = 1, ul = m, mid = 0, ans = -1;\n        while(ll <= ul){\n            mid = (ll + ul) >> 1;\n            if(feasible(mid, nums, ci)){\n                ans = mid;\n                ul = mid - 1;\n            }\n            else\n                ll = mid + 1;\n        }\n        return ans;\n    }\n};\n```
['Array', 'Binary Search', 'C++']