Please clarify the question

  • 5

    I wonder what does it mean to rotate a vector for K greater than the length of the word? can someone explain?

  • 2

    Consider nums = { 3, 8, 5, 2 } and k = 3.

    So, 3 will end up at i=3, 8 will end up at i=0, and so on. k=3 is the largest value k can be for this array, anything larger is redundant.

    Consider k=4 == nums.Length. All of the elements just end up at their original positions after the shift. k=5 just does what k=1 does, and so on.

    So k%nums.Length is just a nice way to get rid of this redundancy. Recall the modulo (%) returns the remainder of x/y. So, 4%4 = 0, 5%4=1, 6%4=2, and so on. Also, if x < y then x%y just returns x.

    Hope this helped!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.