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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Constructive Algorithms
  4. Gaming Array
  5. Discussions

Gaming Array

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • zkobaladze002
    2 years ago+ 0 comments

    JavaScript solution

    function gamingArray(arr) {
        var maxInt = arr[0];
        var counter = 1;
        if(arr.length === 1){
            return "BOB";
        }
        for(let i = 1; i < arr.length; i++){
            if(arr[i] > maxInt){
                maxInt = arr[i];
                counter++
            }
        }
    
        if(counter%2 === 0){
            return "ANDY";
        }
        else{
            return "BOB"
        }
    }
    
    1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature