FastPrepHall of Shifting Tiles

Hall of Shifting Tiles

Adobe logoAdobe● MediumFULLTIMEOA
Learn

Problem statement

A linear corridor contains n tiles numbered from 1 to n. Tile i has an initial direction directions[i], either < or >, and a nonnegative hardness cost costs[i].

For one run, place an orb on a chosen starting tile. Repeat the following steps while the orb remains inside the corridor:

  1. Add the hardness cost of the current tile to the total time.
  2. Flip the current tile's direction: < becomes >, and > becomes <.
  3. Move the orb one tile in the direction that the current tile had before it was flipped.

The run ends when the orb moves to position 0 or n + 1.

Run this process independently from every starting tile. Before each run, restore every direction to its original value. Return an array answer of length n, where answer[i] is the total time accumulated when the orb starts on tile i + 1.

Function

totalEscapeTimes(directions: String, costs: int[]) → long[]

Examples

Example 1

directions = "><"costs = [3, 5]return = [11, 13]

Starting on tile 1 visits tiles 1, 2, 1, so the total is 3 + 5 + 3 = 11. Starting on tile 2 visits tiles 2, 1, 2, so the total is 5 + 3 + 5 = 13.

Example 2

directions = ">><<"costs = [1, 2, 3, 4]return = [9, 23, 27, 16]

For example, the run from tile 2 visits 2, 3, 2, 1, 2, 3, 4, 3, 2, 1. The corresponding costs sum to 23. Every other result is computed from an independent reset of the same initial corridor.

Constraints

  • 1 <= directions.length == costs.length <= 2000
  • directions[i] is either < or >.
  • 0 <= costs[i] <= 10^9
  • All returned totals fit in a signed 64-bit integer.

Source note: User-provided RedNote assessment screenshots showing the reported task.

More Adobe problems

See Adobe hiring insights
public long[] totalEscapeTimes(String directions, int[] costs) {
    // Write your solution here
}
directions"><"
costs[3, 5]
expected[11, 13]
Checking account…