Solve capital selection and grid escape
Problem 1: Maximize Capital After Projects
You are given k (the maximum number of projects you can undertake), initialCapital, an array requiredCapital where requiredCapital[i] is the capital needed to start project i, and an array profit where profit[i] is the profit gained upon completing project i.
You may pick at most k projects. At each selection, you can start any project whose requiredCapital[i] is less than or equal to your current capital. Upon starting a project, you immediately gain profit[i], increasing your current capital.
Return the maximum capital achievable after completing up to k selections.
Constraints & Optimization:
Optimize for n (number of projects) up to 2e5. Justify your data structure choices and analyze the time and space complexity of your solution.
Problem 2: Minimum Time to Exit Sewer
You are given a grid (a 2D character array) and an equally sized heights matrix (a 2D array of non-negative integers).
The grid contains:
'S'(start position)'E'(exit position)'#'(wall - impassable)'.'(open cell)
You start at time 0 from the 'S' position. You can move 4-directionally (up, down, left, right) one cell per minute.
At any minute t, all cells (r, c) where heights[r][c] <= t become flooded and are impassable. This means you cannot enter or stay in a cell if its height is less than or equal to the current time t.
Find the minimum arrival time to the 'E' position before it floods, or return -1 if it's impossible to reach the exit.
Constraints & Optimization:
Discuss the algorithm, its correctness, edge cases, and analyze the time and space complexity for grids up to 5e5 cells.
AI interview prep
Core dilemma
Optimizing resource allocation and pathfinding under dynamically changing environmental constraints, requiring efficient data structures and robust algorithmic choices.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve capital selection and grid escape
Problem 1: Maximize Capital After Projects
You are given k (the maximum number of projects you can undertake), initialCapital, an array requiredCapital where requiredCapital[i] is the capital needed to start project i, and an array profit where profit[i] is the profit gained upon completing project i.
You may pick at most k projects. At each selection, you can start any project whose requiredCapital[i] is less than or equal to your current capital. Upon starting a project, you immediately gain profit[i], increasing your current capital.
Return the maximum capital achievable after completing up to k selections.
Constraints & Optimization:
Optimize for n (number of projects) up to 2e5. Justify your data structure choices and analyze the time and space complexity of your solution.
Problem 2: Minimum Time to Exit Sewer
You are given a grid (a 2D character array) and an equally sized heights matrix (a 2D array of non-negative integers).
The grid contains:
'S'(start position)'E'(exit position)'#'(wall - impassable)'.'(open cell)
You start at time 0 from the 'S' position. You can move 4-directionally (up, down, left, right) one cell per minute.
At any minute t, all cells (r, c) where heights[r][c] <= t become flooded and are impassable. This means you cannot enter or stay in a cell if its height is less than or equal to the current time t.
Find the minimum arrival time to the 'E' position before it floods, or return -1 if it's impossible to reach the exit.
Constraints & Optimization:
Discuss the algorithm, its correctness, edge cases, and analyze the time and space complexity for grids up to 5e5 cells.