Question bank › Strings
Dsa Strings Easy

Character Replacement with Constraints

You are given a string and an integer k. Write a function to determine the length of the longest substring that can be obtained by replacing at most k characters with any other characters. Input: The first line of the input contains a single integer k (0 ≤ k ≤ 100). The second line contains the string s (1 ≤ |s| ≤ 100), consisting of lowercase letters only. Output: Print the length of the longest substring after replacements. Example: Input: 2 abbcccaa Output: 5 (The substring 'bbccc' can be transformed with 2 replacements.)

Key concepts

stringsreplacementconstraints

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.