offices offices numbered 0 to offices - 1, and every one of them is packed. Employees have filed move requests: moves[i] = [from, to] means someone wants to move from office from to office to.
A set of approved requests works only if every office gets exactly as many people moving in as moving out. A request with from = to changes nothing.
Return the largest number of requests that can be approved together.offices=3, moves=[[0, 1], [1, 2], [2, 0], [1, 0]] → 3
The moves 0 → 1, 1 → 2 and 2 → 0 form a loop, so every office stays full. Adding 1 → 0 as well breaks it: two people would enter office 0 and only one would leave.
offices=2, moves=[[0, 0], [0, 1]] → 1
A move within the same office changes nothing, so it can be approved. The move 0 → 1 cannot, since nobody moves back.
offices=4, moves=[[0, 1], [2, 3]] → 0
offices=3, moves=[[0, 1], [1, 2], [2, 0], [1, 0]]
3
Run checks the first 3 tests in your browser. Submit checks all 56 tests on the server, hidden ones included.