File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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 ;
14+ }
15+ }
16+ max = Math .max (max , num );
17+ return ;
18+ }
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+ }
29+ }
You can’t perform that action at this time.
0 commit comments