Data Structures and Algorithms Questions

11 / 13

Longest Substring with At Least K Repeating Characters

Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.

Example 1:

Input: s = "aaabb", k = 3
Output: 3
Explanation: The longest substring is "aaa", as 'a' is repeated 3 times.

Example 2:

Input: s = "ababbc", k = 2
Output: 5
Explanation: The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.

Constraints:

  • 1 <= len(s)<= 104
  • s consists of only lowercase English letters.
  • 1 <= k <= 105
INSTRUCTIONS

  1. Write your code inside a function named longest_substring
  2. Your code should work for all permitted possible values of s and k
  3. There are no partial marks for the question.
  4. Your function must return the output, it should not print the output.
  5. To execute a block on the right side coding panel, please press 'shift'+ 'enter'

def longest_substring(s: str, k: int) -> int:
    # your code goes here
See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...