C++ Interview with a Google engineer.

Islands After K Days of Erosion

Watch someone solve the islands after k days of erosion problem in an interview with a Google engineer and see the feedback their interviewer left them.

Interview Summary

Problem type
Islands After K Days of Erosion
Interview question
Given a 2D grid where 1 represents land and 0 represents water, find the number of islands remaining after K days of erosion. Each day, any land cell adjacent to water becomes water. The challenge involves efficiently calculating how long each land cell survives before being eroded, then counting connected components of cells that survive past K days.

Interview Feedback

Feedback about Verdant Gazelle (the interviewee)
Advance this person to the next round?
Yes
How were their technical skills?
3/4
How was their problem solving ability?
4/4
What about their communication ability?
4/4

Technical: 3 out of 4. I think it’s very important for you to finish writing the code for a working solution, and I think it’s possible you could’ve done this if I accommodate another 10-15 minutes for you to finish writing code, so I don’t think I can rate you any lower 2/4 or higher 4/4 today. For the same reason, I would advance you.
Problem solving: 4 out of 4. You have quite strong problem solving, and pretty much came across a working and optimal solution yourself. You’re very structured in your process, and considered runtime up front. Communication: 4 out of 4. I understood what you were thinking the entire time, with a couple pretty minor stumbles that I don’t think are worth rating you lower at 3/4: once when discussing the innerness solution and I misunderstood, and the second when I think you actually meant BFS since that’s what you talked through but actually meant DFS. I think the latter might be a technical point where you acknowledged you might have overlooked if you were going too fast.

Things you did well:

Areas of improvement:

My advice:

Interview Transcript

Verdant Gazelle: Hello.
Immutable Lightning: Hi, pretty good. So we have about an hour, so we'll spend 45 minutes working on an interview question or two together. We'll save the last 15 minutes or so to share feedback, and we'll just use the next 5 minutes for setup. Verdant Gazelle: Yeah, yeah. I am currently— I've been working in robotics and mostly a lot of platform type stuff. Also, I've done a good bit of motion planning as well. I'm targeting a bunch of C++ roles at self-driving car companies. There's a very famous one that everyone's heard of that was spun out of a FAANG company, and they've asked me to do the interview in C++. It's for an L5 role. However, you know, they have a reputation for kind of down-leveling. So I'm hoping to give a little bit of an L6 signal during the interview as well. Um, and yeah, I've got 10 years of experience.

Problem solution approach

  1. Exploration of the problem using concepts:

    • Simulation of erosion in a grid while tracking visited land.
    • Usage of BFS or DFS for exploring islands.
    • Adjusting calculations based on adjacent cells.
  2. Pseudocode structure:

    // Code Initialization  
    struct Cell {  
        bool isLand;  
        bool isVisited;  
        int distanceFromShore;  
    };  
    
    // Function to calculate remaining islands after K days of erosion  
    int countIslandsAfterErosion(vector<vector<int>>& grid, int K) {  
        // Logic for counting islands  
    }  
    
  3. Main takeaways from coding practice: