Description

Given a ring of characters and a key string, find the minimum steps to spell the key by rotating the ring and pressing center. Return minimum steps.

Examples

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

2 rotations + 2 confirms.

Input:ring = "a", key = "a"
Output:0
Explanation:

Edge case with a single character.

Input:ring = "iotfo", key = "foo"
Output:5
Explanation:

The minimum number of steps to spell 'foo' on ring 'iotfo' is 5, using counterclockwise rotations and confirms.

Constraints

  • 1 ≤ ring.length, key.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!