Epic Interview Question

replace the "a" in a sentence to "the"

Interview Answers

Anonymous

Oct 27, 2011

this is how i would do it, in pseudocode: create a StringBuffer to add individual characters and eventually return. string to char array iterate through the char array if a character is 't', check the next chars to see if they are 'h' and 'e' respectively. if so, just add 'a' and jump to the proper index in the array if character isn't 't', just add to the StringBuffer return StringBuffer to string or some kind of while using indexOf('the'), but using a StringBuffer instead of lots of String concatenations

2

Anonymous

Oct 28, 2011

Simply use string::find and string::replace functions.

Anonymous

Jan 17, 2012

NO need to use String.find(). just use string.replaceAll("the","a");