A code editor shows faint guides that fade with distance from the nearest bookmark. A line of text is a string line, and bookmarks are every position holding the character mark.
Write distanceToMark(line, mark) that returns an array where item i is the distance Math.abs(i - j) from position i to the closest position j with line[j] === mark. mark appears in line at least once.
Input: line = "placeholder", mark = "e" Output: [4,3,2,1,0,1,2,2,1,0,1]
For example position 0 is 4 away from the e at position 4.
Input: line = "aaab", mark = "b" Output: [3,2,1,0]
The only marker is at the end.
1 <= line.length <= 100000mark is a single character that appears in line.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #597 Distance to Nearest Marker. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.