LeetCode, You Did Your Best; I Did Not 😂

Posted
25 Apr 2025
343 reads

Summary

I'm sharing two Data Structures and Algorithms questions I was asked during my interviews at Google, although I unfortunately failed to solve them.

How it went

I have been asked 2 DS/A question in Google up until now, and I failed to solve them horribly 😂

But I wanted to contribute back to LC for helping me do the minimal prepration that I did 😅

So I thought I'd share the questions here for the community.

Questions asked (2)

  1. 01

    Graph Serialization and Deserialization

    Data Structures & Algorithms

    We are given a directed graph with node

    data class Node(
        val value: Int, 
        val outEdges: List<Node>
    )

    We have to implement

    fun serialize(node: Node): List<Int> // represents the entire graph reachable from node
    fun deserialize(serializedList : List<Int>): Node // copy of the original graph
    
    • The serialize() function takes a node and returns a List<Int> representation of the graph.
    • The deserialize() function takes that list and reconstructs the original graph.

    Constrains:

    • There can be duplicate values in different nodes.
  2. 02

    Merge Scrolling Screenshots

    Data Structures & Algorithms

    Imagine building a scrolling screenshot feature. You’re given two screenshots—s1 and s2. You need to merge them into one, by trimming out the overlapping pixels.

    We have to implement

    fun mergeScreenshots(
        s1: Array<IntArray>, 
        s2: Array<IntArray>
    ): Array<IntArray>
    • s1 is always the first screenshot, and s2 is the one taken after.
    • Both screenshots will have the same dimensions (same width & height).

    Test case

    input:
    s1 = [[1,2,3,4],
          [4,5,6,7],
          [7,8,9,0],
          [0,1,2,3]]
    

    s2 = [[7,8,9,0], [0,1,2,3], [3,4,5,6], [6,7,8,9]]

    output: [[1,2,3,4], [4,5,6,7], [7,8,9,0], [0,1,2,3], [3,4,5,6], [6,7,8,9]]

    There are few edge cases in these question which you will also have to keep in mind.

How they prepared

I did minimal preparation with the help of LeetCode.

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Google recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!