MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / backtrack

Method backtrack

FindUniqueBinaryString.java:15–31  ·  view source on GitHub ↗
(String nums[], int n,HashSet<String> set, StringBuilder res)

Source from the content-addressed store, hash-verified

13 return res.toString();
14 }
15 public boolean backtrack(String nums[], int n,HashSet<String> set, StringBuilder res){
16 //base case
17 if(res.length() == n){
18 if(!set.contains(res.toString())){
19 return true;
20 }
21 return false;
22 }
23 for(char ch='0';ch<='1';ch++){
24 res.append(ch);
25 if(backtrack(nums,n,set,res)){
26 return true;
27 }
28 res.deleteCharAt(res.length()-1);
29 }
30 return false;
31 }
32}
33
34

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected