Equal-Length Character Blocks
Updated
Problem statement
Given a string s containing only 'a' and 'b', split it into maximal consecutive blocks of equal characters.
You may add letters only at the beginning or end of an existing block. Return the minimum number of letters that must be added so that every block has the same length.
Function
minAdditionalLetters(s: String) → intExamples
Example 1
s = "babaa"return = 3The blocks have lengths 1, 1, 1, 2. Add one letter to each of the first three blocks to obtain blocks of length 2.
Example 2
s = "bbbab"return = 4The blocks have lengths 3, 1, 1. Add two letters to each shorter block.
Example 3
s = "bbbaaabbb"return = 0All three blocks already have length 3.
Constraints
1 <= s.length <= 40,000scontains only'a'and'b'.
More Deloitte Online Assessment questions
- Seventh Nearest PalindromeOA · Seen May 2026
- Minimum Deletions for a Non-PalindromeOA · Seen Jul 2025
- Minimum-Cost Solar Rooftop AllocationOA · Seen Jul 2025
- Pair Elements with Even SumsOA · Seen Jul 2025
- Count Divisible PermutationsOA · Seen Jan 2025
- Largest Element in an ArrayOA · Seen Nov 2024
- Install Carbon FiltersOA · Seen Oct 2023
- Longest Substring with Even OccurrencesOA · Seen Oct 2023
- Maximum Sum RectangleOA · Seen Apr 2022
- Annual Bank Balance with Monthly Card FeesOA · Seen Jan 2022
Similar questions at other companies
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
- Prepare NotificationMicrosoft · OAMicrosoft interview questions
- Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
- Largest Number With Even Digit FrequenciesDRW · OADRW interview questions
- Minimum Replacements for Unequal Adjacent CharactersIBM · OAIBM interview questions
- Crop Text at a Whole-Word BoundaryAmerican Express · OAAmerican Express interview questions
- Minimum Flips for Even Binary RunsJP Morgan Chase · OAJP Morgan Chase interview questions
- Missing WordsVanguard · OAVanguard interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions