In case you think these questions are not actually asked in Google interviews, I should add that I was asked this very question in Google SDE interview just 6 days ago. I failed to answer this and was consequently rejected. Also, the interviewer asked me nothing other than this question. Nothing about the breadth of work that I have done in different sectors, my interest/passion, personal projects etc. I was so upset after the interview was over and I cried a lot after reaching home. :(
>I was so upset after the interview was over and I cried a lot after reaching home. :(
Yep, this is a side effect of the image Google portrays combined with the idiotic interview process. They cultivate an image of being prestigious both internally (the NIH syndrome is extreme) and externally. They claim that all external experience is irrelevant once you start at the great big G (which is bullshit, but that's beyond the point) so you will just be interviewed on "fundamentals".
So you go in and do you interview, and all of the interviewers ignore your 20 years of developing guidance systems for rockets at NASA and have you write algorithms on a whiteboard to find palindromes or overlapping rectangles while the interviewer emphasizes that the code will be photographed (so don't fuck up the syntax!!).
At this point, an org you think is prestigious has convinced you that your only relevance in the big leagues is these whiteboard questions, which you fumble on because you haven't been grinding on leetcode for the last 2 months. REJECTED. A snap judgement based on your public performance skills has deemed you incapable of handling the very fundamentals of engineering. So what is it you've been doing your whole life?
Wow, an interview should never be so traumatic.. Your experience shows how much the process is broken, one-sided and blind to a person's value and potential. I know it's no consolation, but recently I saw a site with many brilliant people sharing their rejection stories: https://rejected.us/ It just goes to show, if a company cannot see your real worth, don't let it get you down, keep going and prove them wrong.
The market for IT folks is excellent and there are many many great companies out there, most of them not very famous. If you've gotten an interview at Google you will definitively find work elsewhere.
If you couldn't solve that question, maybe you shouldn't work at Google...
def valid(S:str, word:str) -> bool:
s = S
for l in word:
pos = s.find(l)
if pos == -1:
return False
s = s[pos+1:]
if not s:
return False
return True
if __name__ == '__main__':
D = ["able", "ale", "apple", "bale", "kangaroo"]
S = "abppplee"
in_s = {len(w): w for w in D if valid(S, w)}
keys = list(in_s.keys())
sorted(keys)
print(f"longest is {in_s[keys[-1]]}")
Yeah, whenever I see a question like that one, I think it's pretty straightforward but then I wonder if my straightforward solution isn't the "brute force" solution and the interviewer isn't looking for some tricky "elegant" solution. Still, if I were asked that in an interview, I'm sure I'd put together something like your solution; I can't think of a "better" way to solve it.
I was trained by fb for interviewing, the phone screen, sw part. You start with a simple enough problem. See how fast the candidate can come up with a solution. Then complicate the problem to find more stuff. Like, what if you have unlimited memory? What if you have very little memory? etc. You are supposed to look for signals. Can the candidate improve the solution based on some random constraints/hints? Is the candidate good enough with the language they picked (eg, append vs extend in python, or why i copied S into s). We were not looking for tricks and the entire idea that big companies are looking for tricks in their interviews was spread by either people that never been in such an interview or were bad enough to be rejected.