Hackerrank Jumping on the Clouds: Revisited (C++)

C++ :

int jumpingOnClouds(vector<int> c, int k) {
    int energyLeft = 100;

    for(int i = 0; i < c.size(); i+=k){
        if(c[i] == 1){
            energyLeft -= 2; 

    return energyLeft;


Note: Test case 8 (Test case 1 in Run Code, Test case 8 in Submit Code) is bugged! I spend hours trying to cater to test case 8 but to no avail. Even if test case 8 fails, you will still get full marks for this question if you pass all the other test cases.

In the for loop, we start from the the cloud that Aerith starts on (i = 0). Deduct 1 energy from energyLeft if the starting cloud is cumulus, and 2 more energy (for a total of 3) if the cloud is thunderhead.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *