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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Sorting
  4. Running Time of Algorithms
  5. Discussions

Running Time of Algorithms

Problem
Submissions
Leaderboard
Discussions

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

  • slimTlzy
    1 year ago+ 0 comments

    here is my solution

    public static int runningTime(ArrayList<Integer> a) {
            int count = 0;
            for (int i = 1; i < a.size(); i++) {
                if (a.get(i) < a.get(i - 1)) {
                    int temp = a.get(i);
                    a.set(i, a.get(i - 1));
                    a.set(i - 1, temp);
                    count++;
                    i = 0;
                }
            }
            return count;
        }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy