Generating all valid parenthesis
I want to create all valid parenthesis strings given an input number n. For example, if n=3, output should be as follows:
["((()))","(()())","(())()","()(())","()()()"]
My code for this problem is as follows:
private void allParenthesis(List<String> result, int n){
if(n == 1){
result.add("()");
return;
}
allParenthesis(result, n-1);
List<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
System.out.println(newResult+" for n:"+n);
result = new ArrayList<String>(newResult);
}
And I use this function in the following function,
public List<String> generateParenthesis(int n) {
List<String> result = new ArrayList<String>();
allParenthesis(result,n);
return result;
}
But when I input n = 3, I get the following output,
["()"]
Where am I going wrong? Am I missing anything very simple?
java recursion
add a comment |
I want to create all valid parenthesis strings given an input number n. For example, if n=3, output should be as follows:
["((()))","(()())","(())()","()(())","()()()"]
My code for this problem is as follows:
private void allParenthesis(List<String> result, int n){
if(n == 1){
result.add("()");
return;
}
allParenthesis(result, n-1);
List<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
System.out.println(newResult+" for n:"+n);
result = new ArrayList<String>(newResult);
}
And I use this function in the following function,
public List<String> generateParenthesis(int n) {
List<String> result = new ArrayList<String>();
allParenthesis(result,n);
return result;
}
But when I input n = 3, I get the following output,
["()"]
Where am I going wrong? Am I missing anything very simple?
java recursion
Did you try debugging?
– shmosel
Nov 14 '18 at 3:39
Yes, i did ... the print statements print [(()), ()(), ()()] for n:2 [(()), ()(), ()()] for n:3 which suggests that the result list is not being updated properly ... but it should because I modify it inside the function. I am not understanding why it does not get modified after I get the result list for n=2
– mettleap
Nov 14 '18 at 3:41
add a comment |
I want to create all valid parenthesis strings given an input number n. For example, if n=3, output should be as follows:
["((()))","(()())","(())()","()(())","()()()"]
My code for this problem is as follows:
private void allParenthesis(List<String> result, int n){
if(n == 1){
result.add("()");
return;
}
allParenthesis(result, n-1);
List<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
System.out.println(newResult+" for n:"+n);
result = new ArrayList<String>(newResult);
}
And I use this function in the following function,
public List<String> generateParenthesis(int n) {
List<String> result = new ArrayList<String>();
allParenthesis(result,n);
return result;
}
But when I input n = 3, I get the following output,
["()"]
Where am I going wrong? Am I missing anything very simple?
java recursion
I want to create all valid parenthesis strings given an input number n. For example, if n=3, output should be as follows:
["((()))","(()())","(())()","()(())","()()()"]
My code for this problem is as follows:
private void allParenthesis(List<String> result, int n){
if(n == 1){
result.add("()");
return;
}
allParenthesis(result, n-1);
List<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
System.out.println(newResult+" for n:"+n);
result = new ArrayList<String>(newResult);
}
And I use this function in the following function,
public List<String> generateParenthesis(int n) {
List<String> result = new ArrayList<String>();
allParenthesis(result,n);
return result;
}
But when I input n = 3, I get the following output,
["()"]
Where am I going wrong? Am I missing anything very simple?
java recursion
java recursion
asked Nov 14 '18 at 3:38
mettleapmettleap
1,065316
1,065316
Did you try debugging?
– shmosel
Nov 14 '18 at 3:39
Yes, i did ... the print statements print [(()), ()(), ()()] for n:2 [(()), ()(), ()()] for n:3 which suggests that the result list is not being updated properly ... but it should because I modify it inside the function. I am not understanding why it does not get modified after I get the result list for n=2
– mettleap
Nov 14 '18 at 3:41
add a comment |
Did you try debugging?
– shmosel
Nov 14 '18 at 3:39
Yes, i did ... the print statements print [(()), ()(), ()()] for n:2 [(()), ()(), ()()] for n:3 which suggests that the result list is not being updated properly ... but it should because I modify it inside the function. I am not understanding why it does not get modified after I get the result list for n=2
– mettleap
Nov 14 '18 at 3:41
Did you try debugging?
– shmosel
Nov 14 '18 at 3:39
Did you try debugging?
– shmosel
Nov 14 '18 at 3:39
Yes, i did ... the print statements print [(()), ()(), ()()] for n:2 [(()), ()(), ()()] for n:3 which suggests that the result list is not being updated properly ... but it should because I modify it inside the function. I am not understanding why it does not get modified after I get the result list for n=2
– mettleap
Nov 14 '18 at 3:41
Yes, i did ... the print statements print [(()), ()(), ()()] for n:2 [(()), ()(), ()()] for n:3 which suggests that the result list is not being updated properly ... but it should because I modify it inside the function. I am not understanding why it does not get modified after I get the result list for n=2
– mettleap
Nov 14 '18 at 3:41
add a comment |
3 Answers
3
active
oldest
votes
You are losing the results that you have created and are not passing it through the recursion. I have fixed it and simplified to one function. Also using an array list will mean there are duplicates. For eg.
Str = "()";
newResult.add("()"+str); //this will result in ()()
newResult.add(str+"()"); //this will also result in the same
If you want the above results then keep using arraylist. if not i suggest using LinkedHashSet as set dont have duplicates and a linked once so that the order of insertion is maintained. HashSet can be used if you dont care about the ordering of the results.
I have provided both ArrayList and LinkedHashSet versions.
HashSet - No dups
private LinkedHashSet<String> generateParenthesis(int n){
if(n == 1){
LinkedHashSet<String> result = new LinkedHashSet<String>();
result.add("()");
return result;
}
LinkedHashSet<String> result = generateParenthesis(n-1);
LinkedHashSet<String> newResult = new LinkedHashSet<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
ArrayList - keep dups
private ArrayList<String> generateParenthesis(int n){
if(n == 1){
ArrayList<String> result = new ArrayList<String>();
result.add("()");
return result;
}
ArrayList<String> result = generateParenthesis(n-1);
ArrayList<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
You can use this function like so.
LinkedHashSet<String> result = generateParenthesis(3);
System.out.println(result);
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
add a comment |
You are discarding your newResult
.
Change
result = new ArrayList<String>(newResult);
to
result.clear();
result.addAll(newResult);
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
add a comment |
When you do
result = new ArrayList<String>(newResult);
You are updating the variable defined at allParenthesis
,
the one you passed it from generateParenthesis
remains unchanged.
Do this instead
result.clear();
result.addAll(newResult);
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292852%2fgenerating-all-valid-parenthesis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are losing the results that you have created and are not passing it through the recursion. I have fixed it and simplified to one function. Also using an array list will mean there are duplicates. For eg.
Str = "()";
newResult.add("()"+str); //this will result in ()()
newResult.add(str+"()"); //this will also result in the same
If you want the above results then keep using arraylist. if not i suggest using LinkedHashSet as set dont have duplicates and a linked once so that the order of insertion is maintained. HashSet can be used if you dont care about the ordering of the results.
I have provided both ArrayList and LinkedHashSet versions.
HashSet - No dups
private LinkedHashSet<String> generateParenthesis(int n){
if(n == 1){
LinkedHashSet<String> result = new LinkedHashSet<String>();
result.add("()");
return result;
}
LinkedHashSet<String> result = generateParenthesis(n-1);
LinkedHashSet<String> newResult = new LinkedHashSet<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
ArrayList - keep dups
private ArrayList<String> generateParenthesis(int n){
if(n == 1){
ArrayList<String> result = new ArrayList<String>();
result.add("()");
return result;
}
ArrayList<String> result = generateParenthesis(n-1);
ArrayList<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
You can use this function like so.
LinkedHashSet<String> result = generateParenthesis(3);
System.out.println(result);
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
add a comment |
You are losing the results that you have created and are not passing it through the recursion. I have fixed it and simplified to one function. Also using an array list will mean there are duplicates. For eg.
Str = "()";
newResult.add("()"+str); //this will result in ()()
newResult.add(str+"()"); //this will also result in the same
If you want the above results then keep using arraylist. if not i suggest using LinkedHashSet as set dont have duplicates and a linked once so that the order of insertion is maintained. HashSet can be used if you dont care about the ordering of the results.
I have provided both ArrayList and LinkedHashSet versions.
HashSet - No dups
private LinkedHashSet<String> generateParenthesis(int n){
if(n == 1){
LinkedHashSet<String> result = new LinkedHashSet<String>();
result.add("()");
return result;
}
LinkedHashSet<String> result = generateParenthesis(n-1);
LinkedHashSet<String> newResult = new LinkedHashSet<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
ArrayList - keep dups
private ArrayList<String> generateParenthesis(int n){
if(n == 1){
ArrayList<String> result = new ArrayList<String>();
result.add("()");
return result;
}
ArrayList<String> result = generateParenthesis(n-1);
ArrayList<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
You can use this function like so.
LinkedHashSet<String> result = generateParenthesis(3);
System.out.println(result);
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
add a comment |
You are losing the results that you have created and are not passing it through the recursion. I have fixed it and simplified to one function. Also using an array list will mean there are duplicates. For eg.
Str = "()";
newResult.add("()"+str); //this will result in ()()
newResult.add(str+"()"); //this will also result in the same
If you want the above results then keep using arraylist. if not i suggest using LinkedHashSet as set dont have duplicates and a linked once so that the order of insertion is maintained. HashSet can be used if you dont care about the ordering of the results.
I have provided both ArrayList and LinkedHashSet versions.
HashSet - No dups
private LinkedHashSet<String> generateParenthesis(int n){
if(n == 1){
LinkedHashSet<String> result = new LinkedHashSet<String>();
result.add("()");
return result;
}
LinkedHashSet<String> result = generateParenthesis(n-1);
LinkedHashSet<String> newResult = new LinkedHashSet<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
ArrayList - keep dups
private ArrayList<String> generateParenthesis(int n){
if(n == 1){
ArrayList<String> result = new ArrayList<String>();
result.add("()");
return result;
}
ArrayList<String> result = generateParenthesis(n-1);
ArrayList<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
You can use this function like so.
LinkedHashSet<String> result = generateParenthesis(3);
System.out.println(result);
You are losing the results that you have created and are not passing it through the recursion. I have fixed it and simplified to one function. Also using an array list will mean there are duplicates. For eg.
Str = "()";
newResult.add("()"+str); //this will result in ()()
newResult.add(str+"()"); //this will also result in the same
If you want the above results then keep using arraylist. if not i suggest using LinkedHashSet as set dont have duplicates and a linked once so that the order of insertion is maintained. HashSet can be used if you dont care about the ordering of the results.
I have provided both ArrayList and LinkedHashSet versions.
HashSet - No dups
private LinkedHashSet<String> generateParenthesis(int n){
if(n == 1){
LinkedHashSet<String> result = new LinkedHashSet<String>();
result.add("()");
return result;
}
LinkedHashSet<String> result = generateParenthesis(n-1);
LinkedHashSet<String> newResult = new LinkedHashSet<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
ArrayList - keep dups
private ArrayList<String> generateParenthesis(int n){
if(n == 1){
ArrayList<String> result = new ArrayList<String>();
result.add("()");
return result;
}
ArrayList<String> result = generateParenthesis(n-1);
ArrayList<String> newResult = new ArrayList<String>();
for(String str : result){
newResult.add("("+str+")");
newResult.add("()"+str);
newResult.add(str+"()");
}
result.addAll(newResult);
return result;
}
You can use this function like so.
LinkedHashSet<String> result = generateParenthesis(3);
System.out.println(result);
edited Nov 14 '18 at 4:39
answered Nov 14 '18 at 3:55
Mohammad CMohammad C
1,1951312
1,1951312
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
add a comment |
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
Good work, but if you would explain a bit more about your answer, it would be useful for new readers, and this would also improve your answer's credibility.
– PradyumanDixit
Nov 14 '18 at 3:59
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
@PradyumanDixit I was just testing my solution and make changes. mettleap, if you want it to be two functions like your post let me know and i will adjust and add it to the answer. As you can see it can be done in function.
– Mohammad C
Nov 14 '18 at 4:36
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
I understand that somethings can just be done in one line or one method, but a bit of explaining makes it better for the new readers of Stack Overflow, and this I think would be great on our part. This answer looks great. Good job!
– PradyumanDixit
Nov 14 '18 at 4:46
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
Thank you for the answer :)
– mettleap
Nov 14 '18 at 16:45
add a comment |
You are discarding your newResult
.
Change
result = new ArrayList<String>(newResult);
to
result.clear();
result.addAll(newResult);
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
add a comment |
You are discarding your newResult
.
Change
result = new ArrayList<String>(newResult);
to
result.clear();
result.addAll(newResult);
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
add a comment |
You are discarding your newResult
.
Change
result = new ArrayList<String>(newResult);
to
result.clear();
result.addAll(newResult);
You are discarding your newResult
.
Change
result = new ArrayList<String>(newResult);
to
result.clear();
result.addAll(newResult);
answered Nov 14 '18 at 3:55
KartikKartik
3,66231435
3,66231435
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
add a comment |
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
Thanks a lot :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:47
add a comment |
When you do
result = new ArrayList<String>(newResult);
You are updating the variable defined at allParenthesis
,
the one you passed it from generateParenthesis
remains unchanged.
Do this instead
result.clear();
result.addAll(newResult);
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
add a comment |
When you do
result = new ArrayList<String>(newResult);
You are updating the variable defined at allParenthesis
,
the one you passed it from generateParenthesis
remains unchanged.
Do this instead
result.clear();
result.addAll(newResult);
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
add a comment |
When you do
result = new ArrayList<String>(newResult);
You are updating the variable defined at allParenthesis
,
the one you passed it from generateParenthesis
remains unchanged.
Do this instead
result.clear();
result.addAll(newResult);
When you do
result = new ArrayList<String>(newResult);
You are updating the variable defined at allParenthesis
,
the one you passed it from generateParenthesis
remains unchanged.
Do this instead
result.clear();
result.addAll(newResult);
answered Nov 14 '18 at 3:55
JuanJuan
525
525
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
add a comment |
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
Thank you :) ... appreciate your help
– mettleap
Nov 14 '18 at 16:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292852%2fgenerating-all-valid-parenthesis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you try debugging?
– shmosel
Nov 14 '18 at 3:39
Yes, i did ... the print statements print [(()), ()(), ()()] for n:2 [(()), ()(), ()()] for n:3 which suggests that the result list is not being updated properly ... but it should because I modify it inside the function. I am not understanding why it does not get modified after I get the result list for n=2
– mettleap
Nov 14 '18 at 3:41