Media.net SDE intern question for technical round 1

media.net logo
media.net
SDE intern
May 26, 20259 reads

Summary

I was asked the following coding problem during my technical round 1 for the SDE intern position at Media.net.

Full Experience

During my technical round 1 for the SDE intern position at Media.net, I was presented with the following problem:

Interview Questions (1)

Q1
Minimum Recolorings in 2D Grid
Data Structures & AlgorithmsHard

You are given a 2D grid of size m x n, where each cell contains a ball painted with a color, represented by a lowercase English letter ('a' to 'z'). Your goal is to recolor the balls such that:
1. In each row, no color appears more than twice.
2. No two adjacent balls (up, down, left, right) share the same color.

You may recolor any ball using any lowercase letter from 'a' to 'z'

Return the minimum number of recolorings required to make the grid valid according to the constraints.

Example
    Input:
        grid = [
            ['a', 'a', 'a'],
            ['b', 'b', 'b']
        ]
    Output:
        2
Explanation:

In row 0: 'a' appears 3 times, which violates the "at most 2 per row" rule.

Recolor one 'a' to another color (say 'c'), and ensure no two adjacent cells have the same color.

Row 1 also needs 1 change.

So, minimum 2 changes required.

Constraints
1. 1 ≤ m, n ≤ 10
2. grid[i][j] is a lowercase English letter ('a' to 'z')

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!