Permutation game Discussions | | HackerRank

Permutation game

  • + 0 comments

    Python

    @functools.lru_cache(None)
    def PG(arr):
        if list(arr) == sorted(list(arr)):
            return 'Bob' 
        else:
            for i in range(len(arr)):
                if PG(arr[:i]+arr[i+1:]) == 'Bob': 
                    return 'Alice'
            return 'Bob'   
        
    def permutationGame(arr):
        return PG(tuple(arr))