jfaneuff
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
All the +/ inserts cancel out, leaving a combo of number partitions to sum
first digit x N!
first 2 digits (N1)!
first 3 digits (N2)!
Solution works for any number of digits within limits of int range of values for factorial.
public class mymain {
public static int factorial(int f) {
return ((f == 0) ? 1 : f * factorial(f  1));
}
public static void main(String[] args) {
String numbers = "123";
for(int i=0; i<numbers.length(); i++)
{
sum += Integer.parseInt(numbers.substring(0, i+1)) * factorial(Ni);
}
System.out.println("Total sum = " + sum);
}
}

jfaneuff
April 18, 2017 Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
 jfaneuff May 09, 2017