Skip to content

Practice Minimum Cost Homecoming of a Robot in a Grid

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2087
LeetCode Problem

Minimum Cost Homecoming of a Robot in a Grid

Problem Statement

Move the robot from startPos to homePos within the grid, one cell up, down, left, or right per step. A vertical move into row r costs rowCosts[r], and a horizontal move into column c costs colCosts[c]. Return the minimum total cost; costs apply to the entered row or column.

Source: Minimum Cost Homecoming of a Robot in a Grid on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7]
Output
18

# Example 2

Input
startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26]
Output
0

Constraints

m == rowCosts.length
n == colCosts.length
1 <= m, n <= 10^5
0 <= rowCosts[r], colCosts[c] <= 10^4
startPos.length == 2
homePos.length == 2
0 <= startrow, homerow < m
0 <= startcol, homecol < n

Related LeetCode Problems

Practice more problems similar to Minimum Cost Homecoming of a Robot in a Grid.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.