Palantir Technology Interview Question
Software EngineersCountry: United States
Interview Type: Phone Interview
This is a horrible interview question.
evaluate what exactly? There is nothing to evaluate.
And if the example is what was given by the interviewer then the question itself has flaws.
The example implies that W = 6
ONE+TWO = THREE
How can ('O' = 2) + ('T' = 4) = 'T'? In this case 2+4 = 6 which would be 'W'
How can
FOUR +FOUR = EIGHT?
Again you have ('O' = 2) + ('O' = 2) = 4 which equals to 'T' and not 'I' or 'G'
//The complete code
public interface Expression {
public Set<Character> getChars(String in);
public boolean eval(Map <Character, Integer> c);
}
public class ExpressVerify implements Expression{
Map<Character, Integer> maps=new HashMap<Character,Integer>();
String operand1;
String operand2;
String result;
public Set<Character> getChars(String in)
{
Set<Character> vs=new LinkedHashSet<Character>();
for(int i=0;i<in.length();i++)
vs.add(in.charAt(i));
return vs;
}
int get_addition(int val1,int val2)
{
return val1+val2;
}
int getValue(String in1, Map<Character,Integer> maps)
{
Set<Character> v= new LinkedHashSet<Character>();
v= getChars(in1);
Iterator<Character> it=v.iterator();
int j=v.size()-1;
int sum=0;
while(it.hasNext())
{
Character a=it.next();
System.out.print(a);
if (maps.containsKey(a)){
int val= maps.get(a);
sum+=val*Math.pow(10.0, (double)j);
}
else
sum+=0;
j--;
}
System.out.println(sum);
return sum;
}
public boolean eval(Map <Character, Integer> c)
{
int res=get_addition(getValue(operand1,c),getValue(operand2,c));
if (res==getValue(result,c))
return true;
else
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ExpressVerify ev= new ExpressVerify();
ev.maps.put('O', 2);
ev.maps.put('N', 3);
ev.maps.put('E', 1);
ev.maps.put('T', 4);
ev.maps.put('W', 6);
ev.operand1="ONE";
ev.operand2="ONE";
ev.result="TWO";
System.out.println(ev.eval(ev.maps));
System.out.println(ev.maps.values());
}
}
I guess I asked him many times If my understanding is correct as the problem looked really simple . And even after solving , I asked for feedback and he said he was fine with the solution. , he asked me to design another class for multiplication and I did using abstract class.
- akii March 03, 2015Overall I felt I did well , but got a rejection mail in an hour .