Minimum Cost to Move Within a Grid (Akuna Shang Hai π)
Updated
Problem statement
A player stands on a cell within a grid. The player can move to one of four adjacent cells, but the motion is constrained by lasers. To move from one position to another involves a cost: the cost to move from row i to row i Β± 1 is costRows[i] and the cost to move from column j to column j Β± 1 is costCols[j]. Find the minimum cost to move from a starting point to an ending point within the grid.
Function
minCost(rows: int, cols: int, initR: int, initC: int, finalR: int, finalC: int, costRows: int[], costCols: int[]) β int
Complete the function minCost in the editor below.
minCost has the following parameters:
int rows: the number of rows in the gridint cols: the number of columns in the gridint initR: the player's starting rowint initC: the player's starting columnint finalR: the goal's rowint finalC: the goal's columnint costRows[n]: eachcostRows[i]denotes the cost to move between rows i and i + 1.int costCols[m]: eachcostCols[j]denotes the cost to move between columns j and j + 1.
Returns
int: the minimum cost to move from the starting position to the goal
Examples
Example 1
rows = 3cols = 3initR = 0initC = 0finalR = 1finalC = 2costRows = [2, 5]costCols = [6, 1]return = 9Moving from row 0 to row 1 crosses boundary costRows[0] = 2. Moving from column 0 to column 2 crosses boundaries costing 6 and 1. The total is 2 + 6 + 1 = 9.
Example 2
rows = 4cols = 4initR = 1initC = 2finalR = 3finalC = 3costRows = [1, 2, 3]costCols = [7, 8, 9]return = 14Moving from row 1 to row 3 costs costRows[1] + costRows[2] = 2 + 3 = 5. Moving from column 2 to column 3 costs costCols[2] = 9. The total is 14.
Constraints
1 β€ rows, cols β€ 1050 β€ initR, finalR < rows0 β€ initC, finalC < cols0 β€ costRows[i] β€ 104 (0 β€ i < rows-1)0 β€ costCols[j] β€ 104 (0 β€ j < cols-1)
More Akuna Capital interview questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA Β· Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA Β· Seen Dec 2026
- Delivery Management SystemOA Β· Seen Nov 2026
- Count Server ReplacementsOA Β· Seen Nov 2026
- Match Orders by Price and Arrival TimeOA Β· PHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Maximum Remaining Drone PowerOA Β· Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN Β· Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Rolling MetricsOA Β· Seen Oct 2026
- Vowel Substring GameOA Β· Seen Sep 2026
Similar questions at other companies
- Minimum AmountBelvedere Trading Β· OA
- Maximum Number of Workers with Equal Left and Right ShoesTesla Β· OATesla interview questions
- Focus on Efficiency (2024 NG)Google Β· OAGoogle interview questions
- Minimum Cost K-Capable ModelsMicrosoft Β· OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok Β· OATikTok interview questions
- Longest Repeated Letter Block with Adjacent SwapsIntuit Β· OAIntuit interview questions
- Optimal TransferSnowflake Β· OASnowflake interview questions
- Maximum Equalized Substrings After One Adjacent SwapVisa Β· OAVisa interview questions
- Minimize Warehouse Transfer CostAmazon Β· OA
- K-Capable Model SelectionWalmart Β· OAWalmart interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)