FastPrepHall of Shifting Tiles
Problems/Hall of Shifting Tiles

Hall of Shifting Tiles

Adobe logoAdobe● MediumNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source supplies the reset-per-start tile process, pre-flip movement, nonnegative costs and input structure. A later author reply writes the size bound as 2 × 10e3, which is ambiguous. This practice version explicitly uses at most 2,000 tiles and costs at most 10^9; examples and the callable interface are authored.

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

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public long[] totalEscapeTimes(String directions, int[] costs) {
        // Write your solution here
    }
}
Checking account…