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. Game Theory
  4. New Year Game
  5. Discussions

New Year Game

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 22 Discussions, By:

votes

Please Login in order to post a comment

  • ulugbek23
    6 years ago+ 0 comments

    Please, explain me, what does it mean "....both players are moving optimally (playing to win and making no mistakes)."

    8|
    Permalink
  • revad
    5 years ago+ 0 comments

    The problem is not clear enough, not explained what "moving optimally" means, and it seems to be a crucial requirement.

    5|
    Permalink
  • dingma129
    4 years ago+ 0 comments

    If you think about the problem more carefully, only the number of elements that modulo 3=1 or 2 matters.

    This leads to the following simple python solution

    for _ in range(int(input())):
        n = int(input())
        arr = list(map(int, input().split()))
        new_arr=[x%3 for x in arr]
        n_1=new_arr.count(1)
        n_2=new_arr.count(2)
        print('Balsa') if (n_1&1)|(n_2&1) else print('Koca')
    
    4|
    Permalink
  • wani420
    6 years ago+ 0 comments

    @afkaraoglu In your case there are following combinations:

    B:7,18 K:8 Result:25-8=17 B wins B:7,8 K:18 Result:15-18=-3 K wins

    B:8,18 K:7 Result:26-7=19 B wins B:8,7 K:18 Result:15-18=-3 K wins

    B:18,7 K:8 Result:25-8=17, B wins B:18,8 K:7 Result:26-7=19, B wins

    Because both of two players will make no mistakes and try to win, Balsa will choose '18' as her first number and wins the game.

    As a result, the output should be 'Balsa' in your test case.

    4|
    Permalink
  • jxjjligang
    3 years ago+ 0 comments

    I have a simpler solution.

    First, map the original array to its remainder value (modulo 3). Second, reduce the array to the XOR aggregation result. Finally, decide which player wins based on the XOR result equals 0 or not.

    1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature