leetle

Daily challenge for 2025-09-06

249. Shortest Distance to a Character

Write a function solve that, given a string s and a character c that appears in s, returns an array of the shortest distances from each index to the nearest occurrence of c.

Example:
Input: s = 'loveleetcode', c = 'e'
Output: [3,2,1,0,1,0,0,1,2,2,1,0]

Run this challenge interactively in Python or JavaScript when the app loads.