1601. Maximum Number of Achievable Transfer Requests Hard

@problem@discussion
#Array#Backtracking#Bit Manipulation#Enumeration



1/**
2 * [1601] Maximum Number of Achievable Transfer Requests
3 *
4 * We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
5 * You are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.
6 * All buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.
7 * Return the maximum number of achievable requests.
8 *  
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/10/move1.jpg" style="width: 600px; height: 406px;" />
11 * Input: n = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]
12 * Output: 5
13 * Explantion: Let's see the requests:
14 * From building 0 we have employees x and y and both want to move to building 1.
15 * From building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.
16 * From building 2 we have employee z and they want to move to building 0.
17 * From building 3 we have employee c and they want to move to building 4.
18 * From building 4 we don't have any requests.
19 * We can achieve the requests of users x and b by swapping their places.
20 * We can achieve the requests of users y, a and z by swapping the places in the 3 buildings.
21 * 
22 * Example 2:
23 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/10/move2.jpg" style="width: 450px; height: 327px;" />
24 * Input: n = 3, requests = [[0,0],[1,2],[2,1]]
25 * Output: 3
26 * Explantion: Let's see the requests:
27 * From building 0 we have employee x and they want to stay in the same building 0.
28 * From building 1 we have employee y and they want to move to building 2.
29 * From building 2 we have employee z and they want to move to building 1.
30 * We can achieve all the requests. 
31 * Example 3:
32 * 
33 * Input: n = 4, requests = [[0,3],[3,1],[1,2],[2,0]]
34 * Output: 4
35 * 
36 *  
37 * Constraints:
38 * 
39 * 	1 <= n <= 20
40 * 	1 <= requests.length <= 16
41 * 	requests[i].length == 2
42 * 	0 <= fromi, toi < n
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests/
48// discuss: https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn maximum_requests(n: i32, requests: Vec<Vec<i32>>) -> i32 {
54        0
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_1601() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.