PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/C3 AI

Find longest substring with at least k repeats

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in string algorithms, frequency analysis, and algorithmic problem-solving within the coding & algorithms domain, focusing on practical implementation-level skills for manipulating contiguous substrings and character counts.

  • Hard
  • C3 AI
  • Coding & Algorithms
  • Data Scientist

Find longest substring with at least k repeats

Company: C3 AI

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Hard

Interview Round: Technical Screen

### Longest substring where each character appears at least *k* times You are given: - a string `s` consisting of lowercase English letters - an integer `k` Return the **length of the longest substring** of `s` such that **every distinct character in that substring appears at least `k` times** within the substring. If no such substring exists, return `-1`. #### Notes / assumptions - A substring is contiguous. - If `k <= 1`, the answer is `len(s)`. - You should handle edge cases like empty string, `k > len(s)`, and repeated characters. #### Example - `s = "aaabb", k = 3` → longest valid substring is `"aaa"` → return `3`.

Quick Answer: This question evaluates proficiency in string algorithms, frequency analysis, and algorithmic problem-solving within the coding & algorithms domain, focusing on practical implementation-level skills for manipulating contiguous substrings and character counts.

Related Interview Questions

  • Decompress an encoded string - C3 AI (Medium)
C3 AI logo
C3 AI
Aug 9, 2025, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
3
0

Longest substring where each character appears at least k times

You are given:

  • a string s consisting of lowercase English letters
  • an integer k

Return the length of the longest substring of s such that every distinct character in that substring appears at least k times within the substring.

If no such substring exists, return -1.

Notes / assumptions

  • A substring is contiguous.
  • If k <= 1 , the answer is len(s) .
  • You should handle edge cases like empty string, k > len(s) , and repeated characters.

Example

  • s = "aaabb", k = 3 → longest valid substring is "aaa" → return 3 .

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More C3 AI•More Data Scientist•C3 AI Data Scientist•C3 AI Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.