Skip to content

Practice Freedom Trail

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Problem Statement

A circular ring displays the characters of ring, initially with ring[0] at the 12 o'clock pointer. Spell key in order. Rotating the ring by one position clockwise or counterclockwise costs one step. When the next required character reaches the pointer, pressing the center button records it and costs one additional step. The ring stays in its current orientation for the next character. Return the minimum total steps needed to enter all of key.

Source: Freedom Trail on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
ring = "godding", key = "gd"
Output
4

# Example 2

Input
ring = "godding", key = "godding"
Output
13

Constraints

1 <= ring.length, key.length <= 100
ring and key consist of only lower case English letters.
It is guaranteed that key could always be spelled by rotating ring.

Related LeetCode Problems

Practice more problems similar to Freedom Trail.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.