LeetCode, You Did Your Best; I Did Not 😂
- Posted
- 25 Apr 2025
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)
- 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 aList<Int>representation of the graph. - The
deserialize()function takes that list and reconstructs the original graph.
Constrains:
- There can be duplicate
valuesin different nodes.
- The
- 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>s1is always the first screenshot, ands2is 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.