asahai
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class Steps {
public static void main(String[] args) {
total("",5);
}
private static void total(String str,int steps){
if (steps == 0)
System.out.println(str);
if (steps >= 1)
total(1+" "+str,steps-1);
if (steps >= 2)
total(2+" "+str,steps-2);
}
}
1 1 1 1 1
2 1 1 1
1 2 1 1
1 1 2 1
2 2 1
1 1 1 2
2 1 2
1 2 2
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Yes, I tried it. With input =1 , output will be -1 . Same result with input = 2 i.e. -1
- asahai June 26, 2015