import java.util.ArrayList;
class CombinationOf3And4 {
/*
* http://w...content-available-to-author-only...s.org/zoho-interview-set-2-campus/
* Form a number system with only 3 and 4. Find the nth number of the number system.
* e.g. The numbers are: 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434, 443, 444, 3333, 3334, 3343, 3344, 3433, 3434, 3443, 3444 ….
*/
public static void main
(String[] args
) { printCombinations(20);
}
public static void printCombinations(int n){
ArrayList<String> numbers = new ArrayList<String> ();
numbers.add("3");
numbers.add("4");
int currentNumber = 0;
while(numbers.size()<n){
ArrayList<String> threePrefixed = new ArrayList<String>();
ArrayList<String> fourPrefixed = new ArrayList<String>();
for(int i=currentNumber;i<numbers.size();i++){
// Retrieve all numbers.
// For every number create new number with prefix "3" & with prefix "4".
// then push all 3-prefixed-number into array and then 4-prefixed-number
threePrefixed.add("3"+numbers.get(i));
fourPrefixed.add("4"+numbers.get(i));
currentNumber++;
}
numbers.add(s);
}
numbers.add(s);
}
}
System.
out.
println("Printing result"); }
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CgpjbGFzcyBDb21iaW5hdGlvbk9mM0FuZDQgewoKLyoKICogaHR0cDovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnMub3JnL3pvaG8taW50ZXJ2aWV3LXNldC0yLWNhbXB1cy8KICogRm9ybSBhIG51bWJlciBzeXN0ZW0gd2l0aCBvbmx5IDMgYW5kIDQuIEZpbmQgdGhlIG50aCBudW1iZXIgb2YgdGhlIG51bWJlciBzeXN0ZW0uCiAqIGUuZy4gVGhlIG51bWJlcnMgYXJlOiAzLCA0LCAzMywgMzQsIDQzLCA0NCwgMzMzLCAzMzQsIDM0MywgMzQ0LCA0MzMsIDQzNCwgNDQzLCA0NDQsIDMzMzMsIDMzMzQsIDMzNDMsIDMzNDQsIDM0MzMsIDM0MzQsIDM0NDMsIDM0NDQg4oCmLgogKi8KCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0c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