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.
If you notice until both the length of array i.e. 'C' and 'K' are not 'even' or C == K, you have to traverse through the whole array, so you can simply add all the elements of array and then multiply it with 2 to get the energy lost of all 1's and then add it to length of array to get the total energy lost.
Jumping on the Clouds: Revisited
You are viewing a single comment's thread. Return to all comments →
If you notice until both the length of array i.e. 'C' and 'K' are not 'even' or C == K, you have to traverse through the whole array, so you can simply add all the elements of array and then multiply it with 2 to get the energy lost of all 1's and then add it to length of array to get the total energy lost.
Here's my JavaScript Solution