1
- class Solution {
2
- int max =0 ;
3
- public int maximumRequests (int n ,int [][]requests ) {
4
- helper (requests ,0 ,new int [n ],0 );
5
- return max ;
6
- }
7
-
8
- private void helper (int [][]requests ,int index ,int []count ,int num ) {
9
- // Traverse all n buildings to see if they are all 0. (means balanced)
10
- if (index ==requests .length ) {
11
- for (int i :count ) {
12
- if (0 !=i ) {
13
- return ;
1
+ package com .fishercoder .solutions ;
2
+
3
+ public class _1601 {
4
+ public static class Solution1 {
5
+ int max =0 ;
6
+
7
+ public int maximumRequests (int n ,int [][]requests ) {
8
+ helper (requests ,0 ,new int [n ],0 );
9
+ return max ;
10
+ }
11
+
12
+ private void helper (int [][]requests ,int index ,int []count ,int num ) {
13
+ // Traverse all n buildings to see if they are all 0. (means balanced)
14
+ if (index ==requests .length ) {
15
+ for (int i :count ) {
16
+ if (0 !=i ) {
17
+ return ;
18
+ }
14
19
}
20
+ max =Math .max (max ,num );
21
+ return ;
15
22
}
16
- max =Math .max (max ,num );
17
- return ;
23
+ // Choose this request
24
+ count [requests [index ][0 ]]++;
25
+ count [requests [index ][1 ]]--;
26
+ helper (requests ,index +1 ,count ,num +1 );
27
+ count [requests [index ][0 ]]--;
28
+ count [requests [index ][1 ]]++;
29
+
30
+ // Not Choose the request
31
+ helper (requests ,index +1 ,count ,num );
18
32
}
19
- // Choose this request
20
- count [requests [index ][0 ]]++;
21
- count [requests [index ][1 ]]--;
22
- helper (requests ,index +1 ,count ,num +1 );
23
- count [requests [index ][0 ]]--;
24
- count [requests [index ][1 ]]++;
25
-
26
- // Not Choose the request
27
- helper (requests ,index +1 ,count ,num );
28
33
}
29
34
}