Binary search, simple JS solution, commented code
Approach\nIn code comments\n\n# Complexity\n- Time complexity: O((n+m) * logm)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add you
# Approach\nIn code comments\n\n# Complexity\n- Time complexity: O((n+m) * logm)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number[]} changeIndices\n * @return {number}\n */\nvar earliestSecondToMarkIndices = function(nums, changeIndices) {\n    const n = nums.length;\n    const m = changeIndices.length;\n    \n    // r = m + 1 as we want mid to be between 1 to m (inclusive) else \n    // the last element of changeIndices will never be mid\n    let l = 1, r = m + 1; \n    let minSpaceRequired = -1;\n    while (l < r) {\n        let mid = Math.floor((l + r) / 2);\n        if (findSolution(mid) === true) {\n            r = mid;\n            minSpaceRequired = mid;\n        } else {\n            l = mid + 1;\n        }\n    }\n\n    return minSpaceRequired;\n\n    function findSolution(space) {\n        // Calculate last index in changeIndices for each index of nums (1 to n) \n        let last = Array(n).fill(-1);\n        for (let i = 0; i<space; i++) {\n            last[changeIndices[i] - 1] = i; // Indexed 0\n        }\n\n        // Couldn\'t find all positions, hence can\'t mark of of them\n        for (value of changeIndices) { \n            if (value === -1) return false;\n        }\n\n        let available = 0; // Current available decreament operations\n        let markCount = 0;\n\n        // Iterate changeIndices from 0 to space - 1\n        // If we are at last index for current position (changeIndices[i] - 1) -> mark it and decreament available by that position\'s value in nums\n        // Else increament available\n        for (let i = 0; i<space; i++) {\n            if (last[changeIndices[i] - 1] === i) {\n                if (nums[changeIndices[i] - 1] <= available) {\n                    markCount += 1;\n                    available -= nums[changeIndices[i] - 1];\n                }\n            } else {\n                available += 1;\n            }\n        }\n\n        // Returns true if we marked all the positions in nums\n        return markCount === n;\n    }\n    \n};\n```
['Array', 'Binary Search', 'JavaScript']