Question: FInd the time and space complexity of the following code Class solution { Public void validifblocks(int n) { If (n 0) { For (int i
FInd the time and space complexity of the following code
Class solution {
Public void validifblocks(int n) {
If (n <=0) {
Return;
}
List
helper(blocks, n, n);
}
Private void helper(list
If (left ==0 && right == 0) {
print(blocks);
Return;
}
StringBuilder builder = new StringBuilder();
If (left > 0) {
For (int i = 0; i < right - left; i++) {
builder.append ( );
}
blocks.add(builder.append(if {).toString());
helper(blocks, left -1, right);
blocks.remove(blocks.size() - 1);
}
builder.setlength(0);
If (right > left ) {
For (int i = 0; i < right -left -1; i++) {
builder.append( );
}
blocks.add(builder.append(}).toString());
helper(blocks, left, right -1);
blocks.remove(blocks.size() - 1);
}
}
Private void print(list
For (String s : blocks) {
System.out.println(s);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
