FastPrepMinimum Operations to Reduce a Transaction Ledger
Problems/Minimum Operations to Reduce a Transaction Ledger

Minimum Operations to Reduce a Transaction Ledger

Visa logoVisa● EasyFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The deletion rule, minimum-operation objective, and worked trace match the source at about 99%. The result counts operations, not the number of characters left in the reduced ledger.

You are given a lowercase string transactionLedger. In one operation, choose an index whose character is c:

  • If another c exists to its left, remove the nearest such occurrence.
  • If another c exists to its right, remove the nearest such occurrence.

The chosen character is not removed. After the removals, the remaining characters close up while preserving their relative order. Continue until the ledger cannot be reduced further.

Return the minimum number of operations needed to reduce the ledger as much as possible. An operation with no removable occurrence does not help and is never required.

Function

minProcessingSteps(transactionLedger: String) → int

Examples

Example 1

transactionLedger = "baabacaa"return = 3
  1. Choose the b at index 0. Remove the next b at index 3, obtaining baaacaa.
  2. Choose the a at index 2. Remove the nearest equal characters at indices 1 and 3, obtaining bacaa.
  3. Choose the a at index 3. Remove the equal characters at indices 1 and 4, obtaining bca.

No character now has another equal occurrence. Three operations are necessary and sufficient.

Example 2

transactionLedger = "aaaa"return = 2

First choose an interior a to remove two equal neighbors, leaving aa. A second operation removes one of those two characters. One operation cannot remove all three required occurrences.

Example 3

transactionLedger = "xyz"return = 0

The string is already fully reduced because every character is distinct. No operation is needed.

Constraints

  • 1 <= transactionLedger.length() <= 100000
  • transactionLedger contains only lowercase English letters.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
  • Minimum Values with Even Powers of TwoOA · Seen Sep 2026

Similar questions at other companies

  • Maximum String BeautyBank of America · OABank of America interview questions
  • Minimum Substrings Without Repeating CharactersMicrosoft · OAMicrosoft interview questions
  • Find Length of Longest Good SubsequenceWalmart · OAWalmart interview questions
  • Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions
  • Viral Content BalancerTikTok · OATikTok interview questions
  • Find Minimum Time RequiredAmazon · OA
  • Merging PalindromesOld Mission · OA
  • Largest Palindromic Number from Available DigitsMarshall Wace · OAMarshall Wace interview questions
  • Worker Task Assignment Part 1 - Balance WorkloadStripe · ONSITE INTERVIEWStripe interview questions
  • Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int minProcessingSteps(String transactionLedger) {
        // Write your code here.
    }

}
Checking account…