Gaming Array 1

  • + 1 comment

    python3 slow version:

    def gamingArray(arr):
        number_of_moves = 0
        while len(arr) != 0:
            number_of_moves += 1
            arr = arr[:arr.index(max(arr))]
        if number_of_moves % 2 == 0:
            return "ANDY"
        return "BOB"
    

    fast version:

    def gamingArray(arr):
        number_of_moves = 0
        moves = [(0, arr[0])]
        for i, number in enumerate(arr[1:]):
            if number > moves[-1][1]:
                moves.append((i+1, number))
        if len(moves) % 2 == 0:
            return "ANDY"
        return "BOB"