Tap here to switch tabs
Problem
Submissions

Problem: Shortest Distance to Target String in a Circular Array

med
30 min
Try to solve the Shortest Distance to Target String in a Circular Array problem.

Statement

You are given a circular array of strings words and a string target. You are also given an integer startIndex representing your starting position in words.

In a circular array, moving right from the last index leads to the first index, and moving left from the first index leads to the last index.

Starting from startIndex, you can move either left or right by 11 step at a time.

Return the shortest distance needed to reach any index where the string is equal to target. If target does not exist in words, return −1-1.

Constraints:

  • 1≤1 \leq words.length ≤100\leq 100

  • 1≤1 \leq words[i].length ≤100\leq 100

  • words[i] and target consist of only lowercase English letters.

  • 0≤0 \leq startIndex << words.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Distance to Target String in a Circular Array

med
30 min
Try to solve the Shortest Distance to Target String in a Circular Array problem.

Statement

You are given a circular array of strings words and a string target. You are also given an integer startIndex representing your starting position in words.

In a circular array, moving right from the last index leads to the first index, and moving left from the first index leads to the last index.

Starting from startIndex, you can move either left or right by 11 step at a time.

Return the shortest distance needed to reach any index where the string is equal to target. If target does not exist in words, return −1-1.

Constraints:

  • 1≤1 \leq words.length ≤100\leq 100

  • 1≤1 \leq words[i].length ≤100\leq 100

  • words[i] and target consist of only lowercase English letters.

  • 0≤0 \leq startIndex << words.length