We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Jumping on the Clouds: Revisited
Jumping on the Clouds: Revisited
+ 0 comments Here is my c++ solution, you can watch the explanation here : https://youtu.be/retgbr5jSsg
int jumpingOnClouds(vector<int> c, int k) { int position = 0, energie = 100; do{ position = (position + k) % c.size(); energie -= 1 + c[position] * 2; }while(position != 0); return energie; }
+ 0 comments Readable Java 8 Solution:
// Complete the jumpingOnClouds function below. static int jumpingOnClouds(int[] clouds, int jumpLength) { int energy = 100; int cloudsLength = clouds.length; int cloudOn = 0; do{ cloudOn = (cloudOn + jumpLength) % cloudsLength; if(clouds[cloudOn] == 1) energy -= 3; else energy -= 1; }while(cloudOn != 0); return energy; }
+ 0 comments k = 3 [1, 1, 1, 0, 1, 1, 0, 0, 0, 0] Expected Output 80
Shoudn't the expected output here be 94??
+ 0 comments C++ code
int jumpingOnClouds(vector<int> c, int k) { int sizeC = c.size(); int es; int sum; if ((sizeC % k) == 0){ es = sizeC / k; sum = es; for (int i = 0; i < es; i++){ if (c[i*k] == 1){sum = sum + 2;} } } else { es = sizeC * k; sum = sizeC; for (int i = 0; i < sizeC; i++){ int h; if (i*k > sizeC){h = (i*k) % sizeC;} else { h = i*k;} if (c[h] == 1){sum = sum + 2;} } } int result; result = 100 - sum; return result; }
+ 0 comments Is the Discussions tab also used for reporting issues with the problem?
In problem's constraints it is stated that "n % k == 0", but in one of test cases I was given input values of n=10 and k=3, so that constraint should probably be removed.
Load more conversations
Sort 1059 Discussions, By:
Please Login in order to post a comment