first do swap like this if k=3 do 3 tym swap let start: 1 element from front...its index let end: 3rd last elemtn index...k lement from last swap first wiht 3rd last 2nd with second last 3 wiht last now we have list as:-14 2 4 5 3 23 9 7 6 now set ;4th element from last i.e k+1 from front swap these now with first 3 elemtns i.e 5 nad 14 3and 2 23 and 4
so we have: 5 3 23 14 2 4 9 7 6 space complexity is 1;;; time is also n....but confrm it......plz comment if m wrong On Sat, Sep 10, 2011 at 2:09 PM, kumar raja <[email protected]>wrote: > Given an array of 'n' values you need to circular shift it 'k' times > towards left. > > Input : 9 7 6 5 3 23 14 2 4 > output : 5 3 23 14 2 4 9 7 6 > > n=9 , k= 3 > > constraints : Time complexity O(n) > Space complexity O(1) > > The solutions with O(kn) time complexity and > O(n) complexity with O(k) space complexity are already available. > > I want the O(n) solution with constant space.. > -- > Regards > Kumar Raja > M.Tech(SIT) > IIT Kharagpur, > [email protected] > 7797137043. > 09491690115. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
