Sunday, April 3, 2011

Questions

The morning we invited for an interview with div-dev group (Server and tools), there was for interviews and every interview lasted around 45 minutes and each has around 15 minutes interval.

1.) Write a program which can find the first occurrence of any letter in a pattern for a given string:

Eg: If the given string is “ab,def” and pattern is “ef,dx”, the answer would be 3.

public class IndexOf {

int getIndexOf(char[] inputString, char[] pattern){

int indexVal = inputString.length + 1;

HashMap hInputString = new HashMap ();

for(int j = 0; j< inputString.length;j++){

if(!hInputString.containsKey(inputString[j])){

hInputString.put(inputString[j], j);

}

}

for(int j = 0; j< pattern.length;j++){

if(hInputString.containsKey(pattern[j])){

if(indexVal>hInputString.get(pattern[j])){

indexVal = hInputString.get(pattern[j]);

}

}

}

if(indexVal == inputString.length + 1){

indexVal = -1;

}

return indexVal;

}

}

2.) Write a program which can implement tick-tack game.

3.) Write a program which can find first occurrence of a non duplicating character in the given string matching any character in the pattern. Using basic arrays only

Eg: If the given string is “Abbcddefffghh” and the pattern is “gecb”, then the answer should be 4.

4.) Write a program which find the Fibonacci number for a given index.. Write all the boundary conditions? What happen to memory if you give a huge index? What is the technical term do you use to refer when memory is filled (stack overflow)? How do you handle this situation?

int getFilbonacciNumber(int index){

int fibNo = -1;

if(index>=0){

if(index ==0 || index ==1){

return 1;

}else{

return getFilbonacciNumber(index - 1) + getFilbonacciNumber(index-2);

}

}else{

return fibNo;

}

}