Google L4 In-person Interview
Summary
I had an in‑person L4 interview at Google in Bangalore where I was given a mapping question involving placeholder keys and recursive resolution.
Full Experience
Location : BLR Role : L4
I gave my Google in‑person interview today. I wanted to know as per the mistakes what kind of rating [ ie NH/LH/H ] I could get according to you guys.
It was a mapping question where provided a key‑value pair and source string, I was supposed to return the output. In the source string anything that was present between 2 % signs were supposed to be taken as a key.
My mistakes :
- I pointed out all keys might not be present so we will return "-1" as response. The interview said that could also be a valid response. I took a couple of secs to think and till the interviewer said "How about returning an error ?" I went with his idea and implemented that.
- I totally missed that a key's value could have another key present inside it. Eg : X--> "%y%/home". I simply needed to add a recursive call after finding the key and I did that.
- After doing the recursive call, I told him that we might have cycles. I stored earlier occuring keys in a vector and he suggested why not use a unordered_map to save time and space.
What do you guys think ?
Interview Questions (1)
String Placeholder Mapping Replacement
Given a dictionary of key‑value pairs and a source string, replace every placeholder in the source string with its corresponding value. A placeholder is defined as any substring that appears between two % characters (e.g., %key%). The replacement must handle nested placeholders, i.e., a value may itself contain other placeholders that need to be resolved recursively. If a placeholder refers to a key that does not exist, the solution should return an error (or "-1"). The algorithm must also detect cycles (e.g., %a% refers to %b% and %b% refers back to %a%) and handle them gracefully, preferably using a hash map for visited keys to avoid infinite recursion.