You are viewing a single comment's thread. Return to all comments →
O(N^2) complexity
def permutationGame(arr): memo = {} def winner(nums): if tuple(nums) in memo: return memo[tuple(nums)] if sorted(nums) == nums: memo[tuple(nums)] = 'Bob' return 'Bob' for i in range(len(nums)): if winner(nums[:i] + nums[i+1:]) == 'Bob': memo[tuple(nums)] = 'Alice' return 'Alice' memo[tuple(nums)] = 'Bob' return 'Bob' return winner(arr)
Seems like cookies are disabled on this browser, please enable them to open this website
Permutation game
You are viewing a single comment's thread. Return to all comments →
O(N^2) complexity