If you want to rotate an circular array then there could be two approaches. For this code sample we are taking following resources :

a[] – an integer array

n= Number of integers in array a[]

k= Times we want to rotate array. (Every time one is added to the index of element)

First approach : –

Second approach :

Now you can clearly see the difference. Second approach is faster and i think fastest for rotating the array because we are only iterating n times whereas in first approach we are iterating n*k times. If you know better way then comment below.


faltutech

Pursuing MCA from YMCA University, Faridabad

Leave a Reply

Your email address will not be published. Required fields are marked *

Read previous post:
Using Subexpressions in RegEx
Using Subexpressions in RegEx

We need subexpressions for complex and refined output. We can refine our output by grouping the expressions.  E.g. Test Case -...

Close