You are viewing a single comment's thread. Return to all comments →
Javascript solution passed all test cases.
Didn't see what's the catch) Just add one line of code with the counter and the "challenge" is completed .
function processData(input) { let counter = 0; let arr = input.split("\n")[1].split(' ').map(Number); for (let i = 1, j = i; i < arr.length; j = ++i) { while (arr[j] < arr[j-1] && j) { let temp = arr[j-1]; arr[j-1] = arr[j]; arr[j--] = temp; counter++; } } console.log(counter); }
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →
Javascript solution passed all test cases.
Didn't see what's the catch) Just add one line of code with the counter and the "challenge" is completed .