Epic Systems Interview Question
Software DevelopersCountry: United States
Interview Type: Written Test
import java.util.*;
public class permutation{
public static void findSubsets(HashMap hMap,int[] x){
int product=1;
int count=0;
int flag=0;
int noOfSubsets=1<<x.length;
for(int i=1;i<noOfSubsets;i++){
int pos=x.length-1;
int bitmask=i;
product=1;
flag=0;
count=1;
while(bitmask>0){
if((bitmask & 1)==1){
product=product*x[pos];
flag++;
}
bitmask=bitmask>>1;
pos--;
}
System.out.println("");
if((hMap.get(product)==null && flag >1 ))
hMap.put(product,count);
else if(flag>1)
hMap.put(product, -1);
}
}
public static void main(String[] args){
permutation p =new permutation();
int[] x={2,4,8};
HashMap<Integer,Integer> hMap=new HashMap<Integer,Integer>();
p.findSubsets(hMap,x);
for(Map.Entry<Integer, Integer> hMap1 : hMap.entrySet()){
if(hMap1.getValue()==-1)
System.out.println("Not a Color");
}
}
}
import java.util.*;
public class permutation{
public static void findSubsets(HashMap hMap,int[] x){
int product=1;
int count=0;
int flag=0;
int noOfSubsets=1<<x.length;
for(int i=1;i<noOfSubsets;i++){
int pos=x.length-1;
int bitmask=i;
product=1;
flag=0;
count=1;
while(bitmask>0){
if((bitmask & 1)==1){
product=product*x[pos];
flag++;
}
bitmask=bitmask>>1;
pos--;
}
System.out.println("");
if((hMap.get(product)==null && flag >1 ))
hMap.put(product,count);
else if(flag>1)
hMap.put(product, -1);
}
}
public static void main(String[] args){
permutation p =new permutation();
int[] x={2,4,8};
HashMap<Integer,Integer> hMap=new HashMap<Integer,Integer>();
p.findSubsets(hMap,x);
for(Map.Entry<Integer, Integer> hMap1 : hMap.entrySet()){
if(hMap1.getValue()==-1)
System.out.println("Not a Color");
}
}
}
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
public class colourful {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
String temp = num+"";
if((num+"").length()>2){
List<String> number = new ArrayList<String>();
for(int i = 0 ; i<=temp.length()-1;i ++){
number.add(""+temp.charAt(i));
}
ArrayList<String> combinations = makeCombinations(number);
for(String s : combinations){
System.out.println(s);
}
boolean colourful = checkColourful(combinations);
System.out.println(colourful);
}
}
private static boolean checkColourful(ArrayList<String> combinations) {
HashSet<Integer> set = new HashSet<Integer>();
for(String s : combinations){
int value = Integer.parseInt(s);
int product = 1;
while(value!=0){
int temp = value%10;
product = product * temp;
value = value/10;
}
if(set.contains(product)){
return false;
}else{
set.add(product);
}
}
// TODO Auto-generated method stub
return true;
}
private static ArrayList<String> makeCombinations(List<String> number) {
String temp = "";
List<String> templist = new ArrayList<String>();
number.size();
for(int k = 0 ; k< number.size() - 2; k++){
for(int i =0;i<number.size()-1-k;i++){
temp = number.get(i);
for(int j = i+1; j+k<number.size();){
int loopj = j;
for(int x = k;x>=0 && j<number.size(); x--,j++){
temp = temp + number.get(j);
}
templist.add(temp);
temp = number.get(i);
j = loopj +1;
}
}
}
// TODO Auto-generated method stub
return (ArrayList<String>) templist;
}
}
do you mind detailing the property of a number being colorful?
- HardCode March 05, 2015