A word game highlights every place in a line of text text where the letters of a keyword word appear in any order: a slice of text with exactly the same letters as word, each the same number of times.
Write scrambledPositions(text, word) that returns the start index of every such slice, in ascending order. Slices may overlap.
Input: text = "tabbatcab", word = "bat" Output: [0,3]
tab starts at 0 and bat starts at 3.
Input: text = "abab", word = "ab" Output: [0,1,2]
ab, ba, and ab overlap.
1 <= text.length, word.length <= 30000Run 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 #144 Scrambled Keyword Positions. 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.