Google Interview Question | L4 Onsite India (Foreign Interviewer)
Summary
I experienced a friendly and conversational L4 onsite interview at Google India, where I was presented with a coding challenge to implement an image gallery's getNext() function, focusing on handling favorites first.
Full Experience
Follow up: What if markedFavorites[] contains photos strictly in order the photos also are in allImages[]?
(From the above example given by interviewer, you could have easily made that assumption - but they were not meant to be in any such order as per the original question - so you are supposed to ask/write more examples to uncover such test cases or clearly state that you are assuming such and such thing before proceeding with your approach).
The above question might seem too easy - perhaps it should not even belong to L4 onsite rounds!
But remember, interviewers are more interested in how you tackle a problem (even if it is simple), what and how you think, how you clarify expectations and how you arrive at an optimal approach; rather than what data structures you know, which patterns you can identify and which algorithms you can implement!
My interviewer was very friendly and talkative, it felt more like a discussion rather than an interview.
Interview Questions (1)
You're designing a simple image album viewer.
class Image {};
class Gallery {
vector<Image> allImages;
vector<Image> markedFavorites;
Gallery() {
// some setup
}
Image getNext(); // Returns next image
};
You are to implement the getNext() function such that:
- The images from markedFavorites should be returned first.
- Then, return the remaining images from allImages that are not in markedFavorites.
- Each call to getNext() should return the next image in this combined sequence.
Additional information collected through clarifying questions:
- Once the end is reached,
getNext()should return null. getNext()takes no parameters.- You can do some setup in the constructor, but avoid anything too costly.
- Assume that
markedFavorites[]is a subset ofallImages[], and both vectors remain unchanged after construction. - Order among
markedFavorites[]andallImages[]should be maintained.
Example Input:
allImages = {i1, i2, i3, i4, i5, i6, i7, i8, i9, i10};
markedFavorites = {i2, i5, i7};
Expected Sequence of getNext() calls:
i2, i5, i7, i1, i3, i4, i6, i8, i9, i10