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. Fun Game
  5. Discussions

Fun Game

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 41 Discussions, By:

votes

Please Login in order to post a comment

  • h0mesickAlien
    5 years ago+ 1 comment

    For anyone that may be a little confused by the challenge, and failing a test case here or there... think of it this way. The best choice for the player is to choose the index that benefits him the most, but is not as simple as finding the largest un-used number left in the player's array. It might be a smarter strategy to block the other player's largest number. Example:

    Player1nums : 100 200 500 Player2nums : 900 200 50

    Player1 should pick index 0 because it blocks player2 from collecting on that 900.

    Is there a way to assess the benefit of picking a given i value? Find that way of assessing the benefit and you are on your way to solving this.

    12|
    Permalink
  • shreyas_ahir
    5 years ago+ 2 comments

    this is not good they should have explained it without leaving any room for confusion eg:- 2 20 2 1 10000

    6|
    Permalink
  • jimcodeman123
    4 years ago+ 0 comments

    c++ solution

    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct p2 {
        int i , poss ;
        bool operator < ( p2& other ){
            return i < other.i ;
        }
    };
    
    int main()
    {
        int Testcases ;
        scanf("%d",&Testcases);
        for( int t = 0 ; t < Testcases ; t++ ){
            int Number = 0 ;
            scanf("%d",&Number);
            int A[Number+1] , B[Number+1] ;
            for( int r = 0 ; r < Number ; r++ ) scanf( "%d" ,&A[ r ] );
            for( int r = 0 ; r < Number ; r++ ) scanf( "%d" ,&B[ r ] );
            p2 Converted[Number+1] = { 0 } ;
            int P1 , P2 ;
            P1 = P2 = 0 ;
            for( int c = 0 ; c < Number ; c++ ) {
                Converted[ c ].i = A[ c ] + B[ c ] ;
                Converted[ c ].poss = c ;
            }
            
            sort( Converted , Converted+Number );
            
            bool playing = true ;
            
            for( int p = Number - 1 ; p >= 0 ; p-- ){
                if( playing ){
                    P1 += A[ Converted[ p ].poss ] ;
                }else{
                    P2 += B[ Converted[ p ].poss ] ;
                }
                playing = !playing ;
            }
            if( P1 > P2 )printf("First\n");
            else if( P1 < P2 )printf("Second\n");
            else printf("Tie\n");
        }
        return 0;
    }
    
    4|
    Permalink
  • pgmreddy
    6 years ago+ 1 comment

    1

    Another ambiguous English.

    It should be given as below:

    Each value of i can be chosen only once, either by Player 1 or Player 2, not both. The game always ends after N moves.

    2

    One of the 10 tests in Test Case #4 looks goofy.

    2|
    Permalink
  • NAklecha
    6 years ago+ 3 comments

    PYTHON:

    .

    for _ in xrange(input()):
        n,a,b = input(),map(int, raw_input().split()),map(int, raw_input().split())
        s = [a[x] + b[x] for x in xrange(n)]
        add = c = 0
        for i in range(n):
            index = s.index(max(s))
            if c == 0: add += a[index]
            if c == 1: add -= b[index]
            s.pop(index)
            a.pop(index)
            b.pop(index)
            c = 1 - c
        if add > 0: print "First"
        elif add < 0: print "Second"
        else: print "Tie"
    
    2|
    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