Created
July 27, 2021 18:15
When d>n example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let us have an array of n = 3 and d = 4 | |
let samparr = [1,2,3]; | |
// step 1 -> reverse d elements. | |
let samparr = ["out of bounds"] | |
// To resolve this we refactor d as d = d % n, | |
// so d becomes 1 and 1<n so we rotate the array with d as 1. | |
let samparr = [1,2,3]; | |
// step 2 -> reverse n-d elements. | |
let samparr = [1,3,2]; | |
// step 3 -> reverse n elements. we get the rotated array. | |
let samparr = [2,3,1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment