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. Algorithms
  3. Implementation
  4. Circular Array Rotation
  5. Discussions

Circular Array Rotation

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • mehul_sachdeva7 2 years ago+ 0 comments

    found out what the problem was, new JS code:

    function circularArrayRotation(a, k, queries) {
    
        var rarr = [];
        var aind = [];
        var res = [];
    
        for (var i = 0; i < a.length; i++){
            if ((i + k) < a.length) {
                aind[i] = i + k;
            } else {
                aind[i] = (i + k) % a.length;
            }
        }
    
        for (var j = 0; j < a.length; j++) {
            rarr[aind[j]] = a[j];
        }
    
    
        for (var k = 0; k < queries.length; k++){
            res[k] = rarr[queries[k]];
        }
    
        return (res);
    }
    
    0|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature