Microsoft - SDE2 - Coding Round

microsoft logo
microsoft
SDE II
January 1, 20262 reads

Summary

I was presented with a complex coding problem during my Microsoft SDE2 coding round, requiring me to determine the earliest day a dynamically changing mountain range becomes passable.

Full Experience

You are given a mountain range represented by an array of length N, where each element represents the initial altitude at that position.

  • Initial Altitudes: altitude = [1, 2, 3, 2, 0]
  • Starting Position: You begin at index 0.

You are given a days matrix, where each row represents a single day and each column corresponds to the amount of snowfall at that specific length (index).

  • Snowfall: If the value for a day is greater than 0, the altitude at that index increases by that amount.
  • Melting: If there are two consecutive days with 0 snowfall at a specific index, the snow begins to melt, and the altitude at that position decreases by 1 unit.

Example Calculation:

  • Day 1: days[0] = [1, 0, 1, 2, 1]
  • New Altitudes: [2, 2, 4, 4, 1] (Initial + Day 1 snow)
  • Day 2: days[1] = [1, 0, 1, 1, 0]
  • At index 1, there have been 2 consecutive days of 0 snowfall. Therefore, it melts by 1.
  • New Altitudes: [3, 1, 5, 5, 1]

A person can only move from index to index if the altitude difference is manageable:

  • This means you can only climb up 1 unit or climb down 1 unit at a time.

Find the earliest day on which the mountain range becomes passable. If there are multiple ways to pass, find the path that requires the minimum number of climbs.

Interview Questions (1)

Q1
Mountain Range Passability with Dynamic Altitudes
Data Structures & AlgorithmsHard

You are given a mountain range represented by an array of length N, where each element represents the initial altitude at that position.

  • Initial Altitudes: altitude = [1, 2, 3, 2, 0]
  • Starting Position: You begin at index 0.

You are given a days matrix, where each row represents a single day and each column corresponds to the amount of snowfall at that specific length (index).

  • Snowfall: If the value for a day is greater than 0, the altitude at that index increases by that amount.
  • Melting: If there are two consecutive days with 0 snowfall at a specific index, the snow begins to melt, and the altitude at that position decreases by 1 unit.

Example Calculation:

  • Day 1: days[0] = [1, 0, 1, 2, 1]
  • New Altitudes: [2, 2, 4, 4, 1] (Initial + Day 1 snow)
  • Day 2: days[1] = [1, 0, 1, 1, 0]
  • At index 1, there have been 2 consecutive days of 0 snowfall. Therefore, it melts by 1.
  • New Altitudes: [3, 1, 5, 5, 1]

A person can only move from index to index if the altitude difference is manageable:

  • This means you can only climb up 1 unit or climb down 1 unit at a time.

Find the earliest day on which the mountain range becomes passable. If there are multiple ways to pass, find the path that requires the minimum number of climbs.

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!