Get Optimal String Length

Problem Overview

  • Find the maximum length of a string built from 'A' and 'B' under run-length and total count limits.
  • Input: countA, countB, maxA, maxB; Output: long integer length; Constraints: 0 ≤ all ≤ 1e6.
  • Each run of 'A' ≤ maxA and each run of 'B' ≤ maxB; total 'A's ≤ countA and 'B's ≤ countB.
  • Real-world context: HackerRank trivia scenario; classic string construction problem for coding interview prep.
  • Source: Ibm interviews; a practical interview question often seen in problem sets.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: