Practice Shortest Distance to Target String in a Circular Array
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
You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning. Starting from startIndex, you can move to either the next word or the previous word with 1 step at a time. Return the shortest distance needed to reach the string target. If the string target does not exist in words, return -1.
Source: Shortest Distance to Target String in a Circular Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
words = ["hello","i","am","leetcode","hello"], target = "hello", startIndex = 1
1
# Example 2
words = ["a","b","leetcode"], target = "leetcode", startIndex = 0
1
# Example 3
words = ["i","eat","leetcode"], target = "ate", startIndex = 0
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Shortest Distance to Target String in a Circular Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.