A short-code generator cuts a long random string s into candidate codes: every slice of exactly 3 neighboring characters. A slice is usable only if its three characters are all different.
Write countUsableCodes(s) that returns how many slices of length 3 have no repeated character. Slices at different positions count separately, even if they spell the same code.
Input: s = "xyzzaz" Output: 1
The slices are xyz, yzz, zza, zaz; only xyz has three different characters.
Input: s = "aababcabc" Output: 4
abc, bca, cab, abc are usable.
0 <= s.length <= 100000s contains lowercase letters and digits.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 #128 Distinct Three-Letter Slices. 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.