A log viewer highlights every occurrence of the search term as you type. Logs can be 100,000 characters long, so the search must be fast even for terms like aaab in text like aaaa....
Write findAll(text, term) that returns every index where term starts in text, in increasing order. Matches may overlap: aa appears at 0, 1, and 2 in aaaa. Return an empty array if there are none.
Input: text = "GET /api GET /app", term = "GET" Output: [0,9]
GET starts at index 0 and index 9.
Input: text = "aaaa", term = "aa" Output: [0,1,2]
Overlapping matches all count.
0 <= text.length <= 10^51 <= term.length <= 10^4Run 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 #613 Highlight Every Match. 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.