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 →

  • qianyaonan 5 years ago+ 0 comments

    Good thinking! I guess it could be handled with another array logically. My two cents.

        ......
        int[] getArray = new int[n];
        for (int i = 0; i < n; i++) {
            getArray[i] = scan.next();
        }
        for (int i = 0; i < n; i++) {
            array[(i + n - d) % n] = getArray [i];
        }
        for(int i = 0; i < n; i++) {
            System.out.print(array[i] + " ");
        }      
    
    19|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature