Regarding the question about Rotating Arrays on a platform like Leetcode (array-646), I have encountered an issue. When I provide the answer as [5,6,7,1,2,3,4]
and check it by using console.log(ans)
in my VSCode editor, it displays the correct output. However, when I submit this answer on Leetcode, it doesn't recognize it and keeps insisting that my answer should be [1,2,3,4,5,6,7]
. How can I modify my solution so that Leetcode understands and accepts it?
const k = 3;
const nums = [1, 2, 3, 4, 5, 6, 7];
var rotate = function (nums, k) {
var FN = [];
var LN = [];
for (i = 0; i < nums.length - k; i++) {
FN.push(nums[i]);
}
console.log("FN:", FN);
for (j = k; j > 0; j--) {
LN.push(nums[nums.length - j]);
}
console.log("LN:", LN);
const ans = [].concat(LN, FN);
console.log(ans);
}