NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

You are designing a game with n levels arranged in sequence. You are given two integer arrays layers and energy of length n, and an integer K representing your starting energy.

When you begin from level i, you attempt levels i, i+1, i+2, ... in order. At each level j, you consume layers[j] energy. If your remaining energy is at least energy[j] after consuming, you pass the level and score one point; otherwise, you fail and immediately stop, unable to continue to any further levels.

Each run is independent: you always start with K energy regardless of which level you begin from.

Test Cases
Input
Output
Expected