2025-08-15 16:25:44 +0300 MSK
Minimum Distance to the Target Element
Links
Code
class Solution:
def getMinDistance(self, nums: List[int], target: int, start: int) -> int:
length = len(nums)
dist = 0
while dist < length:
left, right = start - dist, start + dist
if left >= 0 and nums[left] == target:
return dist
if right < length and nums[right] == target:
return dist
dist += 1
raise Exception