Skip to main content
All Questions

Compute the total time for an orb starting on each tile of a corridor to escape.

Unlock detailed company stats for this questionUpgrade

A linear corridor of n tiles, numbered 1 to n. Each tile i has a direction s[i], either '<' (left) or '>' (right), and a nonnegative integer hardness cost c[i]. An orb placed on tile i immediately accumulates time c[i], then tile i flips its direction ('<' becomes '>' and vice versa), then the orb moves one tile in the direction tile i had before it was flipped. This repeats until the orb leaves the corridor, landing at position 0 or n+1.

Answer n independent queries: for every starting position i (1 <= i <= n), compute the total time (sum of hardness costs of visited tiles) until the orb escapes. The corridor resets to its initial directions before each query.

Input: line 1 is n; line 2 is a string s of length n of '<' and '>'; line 3 is n space-separated integers c1 ... cn.

Format · Online assessment.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.