BINARY SEARCH 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: O(NlogN)\n- Space complexity: O(N)\n# Code\n```\nclass Solution {\n    public boolean isPossible(int[] nums, int[] changeIndices, int seconds) {\n        int n = nums.length;\n        int[] last = new int[n + 1];\n        Arrays.fill(last, -1);\n\n        for (int i = 0; i < seconds; i++) {\n            last[changeIndices[i] - 1] = i;\n        }\n\n        int marked = 0;\n        int operations = 0;\n        for (int i = 0; i < seconds; i++) {\n            if (i == last[changeIndices[i] - 1]) {\n                if (nums[changeIndices[i] - 1] > operations) {\n                    return false;\n                }\n                operations -= nums[changeIndices[i] - 1];\n                marked++;\n            } else {\n                operations++;\n            }\n        }\n        return marked == n;\n    }\n\n    public int earliestSecondToMarkIndices(int[] nums, int[] changeIndices) {\n        int n = nums.length;\n        int m = changeIndices.length;\n        int low = 0, high = m + 1;\n        \n        while (low < high) {\n            int mid = (low + high) / 2;\n            if (isPossible(nums, changeIndices, mid)) {\n                high = mid;\n            } else {\n                low = mid + 1;\n            }\n        }\n        \n        if (high == m + 1) {\n            return -1;\n        }\n        return high;\n    }\n}\n\n```
['Array', 'Binary Search', 'Java']