1601. Maximum Number of Achievable Transfer Requests
https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests/
Python
from itertools import combinations
class Solution:
def maximumRequests(self, n: int, requests: List[List[int]]) -> int:
unchanged = sum([1 for req in requests if req[0] == req[1]])
reqs = [req for req in requests if req[0] != req[1]]
ans = 0
for i in range(len(reqs)+1):
for combs in list(combinations(reqs, i)):
if not combs:
continue
movement = [0] * n
for egress, ingress in combs:
movement[egress] += 1
movement[ingress] -= 1
if set(movement) == {0}:
ans = max(ans, len(combs))
return ans + unchanged