LeetCode, You Did Your Best; I Did Not 😂

google logo
google
April 25, 20255 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.

Full Experience

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.

Interview Questions (2)

Q1
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.
Q2
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.

Preparation Tips

I did minimal preparation with the help of LeetCode.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

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