Skip to content

Commit abd9125

Browse files
committed
Added solutions for spraoi
1 parent 6297f2d commit abd9125

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.interviews.preparation.spraoi;
5+
6+
import java.util.Arrays;
7+
import java.util.List;
8+
9+
/**
10+
* @author Kanahaiya Gupta
11+
*
12+
*/
13+
public class CoinChange {
14+
public static void main(String[] args) {
15+
Integer actual = CoinChange.countChange(4,Arrays.asList(1,2));
16+
System.out.println(actual);
17+
}
18+
public static Integer countChange( Integer money,List<Integer> coins ) {
19+
int noOfcoins=coins.size();
20+
return countNumberOfWays(coins,noOfcoins,money);
21+
}
22+
/**
23+
* @param coins
24+
* @param noOfcoins
25+
* @param money
26+
* @return
27+
*/
28+
private static Integer countNumberOfWays(List<Integer> coins, int noOfcoins, Integer money) {
29+
if(money==0)return 1;
30+
if(money<0)return 0;
31+
if(noOfcoins<=0 && money>=1)return 0;
32+
return countNumberOfWays(coins,noOfcoins-1,money)+countNumberOfWays(coins,noOfcoins,money-coins.get(noOfcoins-1));
33+
}
34+
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.interviews.preparation.spraoi;
5+
6+
/**
7+
* @author Kanahaiya Gupta
8+
*
9+
*/
10+
public class IntegerToRomanNumberConverstion {
11+
public String convertIntToRoman(int num){
12+
String m[] = {"", "M", "MM", "MMM"};
13+
String c[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
14+
String x[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
15+
String i[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
16+
17+
String thousands = m[num/1000];
18+
String hundereds = c[(num%1000)/100];
19+
String tens = x[(num%100)/10];
20+
String ones = i[num%10];
21+
22+
String ans = thousands + hundereds + tens + ones;
23+
return ans;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)