Tap here to switch tabs
Problem
Submissions

Problem: Minimum Distance to the Target Element

med
30 min
Try to solve the Minimum Distance to the Target Element problem.

Statement

Given a 00 indexed integer array nums and two integers target and start, find an index i such that nums[i] == target and ∣i−|i - start∣| is minimized.

Return the minimum value of ∣i−|i - start|$.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤104\leq 10^4

  • 0≤0 \leq start << nums.length

  • target is in nums.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Distance to the Target Element

med
30 min
Try to solve the Minimum Distance to the Target Element problem.

Statement

Given a 00 indexed integer array nums and two integers target and start, find an index i such that nums[i] == target and ∣i−|i - start∣| is minimized.

Return the minimum value of ∣i−|i - start|$.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤104\leq 10^4

  • 0≤0 \leq start << nums.length

  • target is in nums.