Skip to the code
cf.
+50 XP

#149 Longest Slice With Every Letter Repeated

hard

A typing tutor looks for practice passages inside a text s: a slice of neighboring letters where every letter that appears in the slice appears at least k times.

Write longestRepeatedSlice(s, k) that returns the length of the longest such slice, or 0 if there is none.

Example 1

Input: s = "aaabb", k = 3
Output: 3

aaa works; including any b would need three bs.

Example 2

Input: s = "ababbc", k = 2
Output: 5

ababb has two as and three bs.

Constraints

  • 0 <= s.length <= 10000
  • s contains lowercase letters only.
  • 1 <= k <= 10000
Saved in this browser

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).