421. Minimum Suspension Strength
Asked in
Minimum Suspension Strength

A warehouse robot moves across a rectangular floor divided into tiles. Each tile has a surface resistance value.

The strain caused by moving between two neighboring tiles is the absolute difference between their resistance values. The suspension strength needed for a route is the largest strain produced by any move on that route.

Find the minimum suspension strength that allows the robot to travel from the top-left tile to the bottom-right tile.

Class

WarehouseRobotRoutePlanner

Method

minimumSuspensionStrength

int minimumSuspensionStrength( List<String> surfaceResistance )

Parameters

  • surfaceResistance: A list of strings representing the warehouse floor. Each string contains one row of comma-separated resistance values.

Returns

Return the minimum suspension strength required to reach the bottom-right tile from the top-left tile.

Input Format

  • Each element of surfaceResistance represents one row.
  • Values within a row are separated by commas.
  • For example, "5,8,12" represents a row containing the resistance values 5, 8, and 12.

Movement Rules

  • The robot starts at the top-left tile (0, 0).
  • The destination is the bottom-right tile.
  • The robot may move one tile up, down, left, or right.
  • Diagonal movement is not allowed.
  • The strain of a move is the absolute difference between the resistance values of the current tile and the next tile.
  • The required strength for a route is the largest strain among all moves in that route.
  • If the floor contains only one tile, return 0.

Constraints

  • 1 ≤ surfaceResistance.size() ≤ 100
  • Each string contains between 1 and 100 comma-separated integers.
  • Every row contains the same number of values.
  • 1 ≤ resistance value ≤ 1,000,000
  • Each row contains only integers and commas.

Examples

Example 1

minimumSuspensionStrength( surfaceResistance = ["6,2,3", "7,12,4", "8,9,5"] )

Output: 4

The robot can follow the values 6 → 2 → 3 → 4 → 5. The move strains are 4, 1, 1, 1, so this route requires strength 4. No route can use a smaller maximum strain.

Example 2

minimumSuspensionStrength( surfaceResistance = ["20,21,30", "18,40,29", "17,16,15"] )

Output: 2

The robot can follow the values 20 → 18 → 17 → 16 → 15. The largest strain on this route is 2.

Example 3

minimumSuspensionStrength( surfaceResistance = ["5", "11", "8", "12"] )

Output: 6

Only one route exists. Its move strains are 6, 3, 4, so the required suspension strength is 6.

Example 4

minimumSuspensionStrength( surfaceResistance = ["250"] )

Output: 0

The starting tile is also the destination, so the robot does not make any move.



Please use Laptop/Desktop or any other large screen to add/edit code.