Abhishek

Abhishek

  • 1.1k
  • 592
  • 77.7k

Array rotation problem

Jan 16 2017 9:15 AM
There is an array,a[ ] of n elements and is rotated in circular right direction for k times.
m in any index of an element in that array i.e. <= <= n .

then to get that mth element 

FORMULA is
a[m] = a[ (( m - k ) % n + n ) % n ]
 
What is the logic behind that formula? 

Answers (1)