Pergunta de entrevista da empresa Epic

decide whether the enter should be accepted or not for a passcode, one number missing is permitted, can be missed several times, 18687 is the passcode, then 167 is accepted, the rest should be right and in right sequence.

Respostas da entrevista

Sigiloso

27 de out. de 2011

recursive solution starting from the back of the integer, digit by digit: public boolean rec(int pass, int entered) { return recHelper(pass, entered, -1); } public boolean recHelper(int pass, int entered, int numToSkip) { if(pass == 0 && entered == 0) return true; if((pass == 0 ^ entered == 0) && (numToSkip != -1)) return false; if(pass % 10 == entered % 10) return rec(pass/10, entered/10, numToSkip); else { if(numToSkip == -1) return rec(pass/10, entered/10, pass % 10); else if(pass % 10 == numToSkip) return rec(pass/10, entered/10, numToSkip); return false; } }

2

Sigiloso

27 de out. de 2011

sorry. i'm missing the situation if one of the numbers is 0.

Sigiloso

27 de out. de 2011

sorry. i'm missing the situation if one of the numbers is 0.

Sigiloso

13 de ago. de 2012

It's a easy one. Collect the digit sets for both input strings and see whether there is only one difference. And then get rid of the difference and compare them.