We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Data Structures
  3. Arrays
  4. Left Rotation
  5. Discussions

Left Rotation

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • ajaycarnet 4 years ago+ 0 comments

    This is my C# sharp code.

            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]);
            int k = int.Parse(s1[1]);
    
            string[] s = Console.ReadLine().Split(' ');
            int[] array = new int[n];
    
            ////pre-rotation of array method:
            //-----------------------------------Right rotation
            //for (int i = 0; i < n; i++)
            //{
            //    array[(i + k) % n] = int.Parse(s[i]);
            //}
    
            //------------------------------------Left rotation
            for (int i = 0; i < n; i++)
            {
                array[(i + (n-k)) % n] = int.Parse(s[i]);
            }
    
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(array[i]+" ");
            }
    
    6|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature