You are viewing a single comment's thread. Return to all comments →
why it says it is wrong?
function processData(input) { //Enter your code here function processArray(arr) { arr.sort((a, b) => a - b); const n = arr.length; const mid = Math.floor((n + 1) / 2) - 1; [arr[mid], arr[n - 1]] = [arr[n - 1], arr[mid]]; for (let start = mid + 1, end = n - 2; start < end; start++, end--) { [arr[start], arr[end]] = [arr[end], arr[start]]; } } const lines = input.trim().split('\n'); const k = parseInt(lines[0], 10); let currentLine = 1; for (let t = 0; t < k; t++) { const arr = lines[currentLine + 1].split(' ').map(Number); processArray(arr); console.log(arr.join(' ')); currentLine += 2; } }
Your Output (stdout) 1 2 3 7 6 5 4 Expected Output 1 2 3 7 6 5 4
Seems like cookies are disabled on this browser, please enable them to open this website
Zig Zag Sequence
You are viewing a single comment's thread. Return to all comments →
why it says it is wrong?
Your Output (stdout) 1 2 3 7 6 5 4 Expected Output 1 2 3 7 6 5 4