Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 1182. Shortest Distance to Target Color
Given an array of colored values and multiple queries (index, target color), return for each query the minimum absolute distance from the index to any element of that color, or -1 if it doesn't exist. The challenge is to handle many queries efficiently by preprocessing the positions of each color so you can quickly find the nearest occurrence per query.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.