FastPrepLongest Repeated Letter Block with Adjacent Swaps
Problems/Longest Repeated Letter Block with Adjacent Swaps

Longest Repeated Letter Block with Adjacent Swaps

Intuit logoIntuit● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Intuit full-time online assessment. Our task is about 90% the same as the report's caption. The report describes adjacent swaps and gathering equal letters. We chose the lowercase alphabet, the limits on the numbers, the function interface and complete examples.

You are given a string s and a non-negative integer k. In one operation, swap the characters at two adjacent positions.

After at most k operations, choose any letter and any contiguous block consisting only of that letter. Return the maximum possible length of such a block.

You may leave some occurrences of the chosen letter outside the block. Characters cannot be inserted, deleted, or replaced, and each adjacent swap costs one operation. You do not have to use the entire budget.

Practice domain

For this exercise, assume s is nonempty and contains only lowercase English letters. The result is the block length, not a transformed string.

Function

longestRepeatedBlock(s: String, k: int) → int

Examples

Example 1

s = "aabaa"k = 2return = 4

Swap the middle b rightward twice: aabaa → aaaba → aaaab. The four as form one block. No block can have length five because the string has only four copies of a.

Example 2

s = "ababa"k = 1return = 2

One swap can produce aabba, whose longest block has length two. Gathering all three as requires two adjacent swaps, so length three is unavailable.

Example 3

s = "abcabc"k = 0return = 1

With no swaps allowed, every existing block has length one.

Constraints

  • For this exercise, assume 1 <= s.length <= 2000.
  • s contains only characters from a through z.
  • For this exercise, assume 0 <= k <= 10^9.

More Intuit Online Assessment questions

  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
  • Parse Router LogsOA · Seen Oct 2026
  • Maximum Square-Free DivisorOA · Seen Oct 2026
  • Two Tribes from Taller-Person CountsOA · Seen Oct 2026
  • Shortest Path from an Encoded GraphOA · Seen Sep 2026
  • Oldest and Youngest EmployeesOA · Seen Sep 2026
  • Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
  • Submask Sum QueriesOA · Seen Sep 2026
  • Alien DictionaryOA · Seen Sep 2026

Similar questions at other companies

  • Maximum Equalized Substrings After One Adjacent SwapVisa · OAVisa interview questions
  • Minimum Number of Non-Empty Disjoint SegmentsIBM · OAIBM interview questions
  • Maximum Number of Workers with Equal Left and Right ShoesTesla · OATesla interview questions
  • Tiktok Viral ChallengeTikTok · OATikTok interview questions
  • Lexicographically Largest IdentifierAmazon · OA
  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • Incident MonitorStripe · OAStripe interview questions
  • Binary CircuitAkuna Capital · OAAkuna Capital interview questions
  • Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
  • Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions

Interview reports that mention this question

  • Intuit OA: What It Tests (2026)

Intuit interview experiences

  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public int longestRepeatedBlock(String s, int k) {
        // write your code here
    }
}
Checking account…