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
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Interview Preparation Kits
  3. 3 Months Preparation Kit
  4. Week 6
  5. Gaming Array 1

Gaming Array 1

Problem
Submissions
Leaderboard
Discussions
Editorial
HackerRank Logo
|
  1. Prepare
  2. Interview Preparation Kits
  3. 3 Months Preparation Kit
  4. Week 6
  5. Gaming Array 1
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

Andy wants to play a game with his little brother, Bob. The game starts with an array of distinct integers and the rules are as follows:

  • Bob always plays first.
  • In a single move, a player chooses the maximum element in the array. He removes it and all elements to its right. For example, if the starting array , then it becomes after removing .
  • The two players alternate turns.
  • The last player who can make a move wins.

Andy and Bob play games. Given the initial array for each game, find and print the name of the winner on a new line. If Andy wins, print ANDY; if Bob wins, print BOB.

To continue the example above, in the next move Andy will remove . Bob will then remove and win because there are no more integers to remove.

Function Description

Complete the gamingArray function in the editor below.

gamingArray has the following parameter(s):

  • int arr[n]: an array of integers

Returns
- string: either ANDY or BOB

Input Format

The first line contains a single integer , the number of games.

Each of the next pairs of lines is as follows:

  • The first line contains a single integer, , the number of elements in .
  • The second line contains distinct space-separated integers where .

Constraints

  • Array contains distinct integers.

For of the maximum score:

  • The sum of over all games does not exceed .

For of the maximum score:

  • The sum of over all games does not exceed .
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website