Amazon Interview Question
Front-end Software EngineersCountry: India
Interview Type: In-Person
We can use "Knuth Morris" algorithm to find the pattern index and then replace the whole required word ("TU" in this case) by required string..
I told 2 every1 tat use simple logic,,jst look at ths..
cpy and paste in browxy site
import java.io.*;
public class Test{
public static void main(String args[]){
String Str="STUN";
System.out.print("Return Value :" );
System.out.println(Str.replaceFirst("TU", "KO" ));
}
}
OUTPUT:
Return Value :SKON
It's so interesting that for the same position from same companies... some ppl get easy questions some ppl get crazy ones (that require specific knowledge of things like Fenwick trees).
No wonder Peter Norvig said when he reviewed Google's hiring process and claimed it was very random (actually he said the ppl who scored the best were worse employees than the ones who barely got in).
if(str[i]=='T'&&str[i+1]=='U'
- shoban September 20, 2013{
str[i]='K';
str[i+1]='O'
}