Strings with equal number of 'A's and 'B's

Published: October 24, 2022, updated: January 1, 2025

Given a file containing strings that contains random ASCII characters, find all strings that contain the same amount of ‘A’ and ‘B’ characters, called AB-Equal.

Some examples:

ABABABjhkdsgisfgjoBBAABBA
BBAAaslkjhdlkajlkasjdlkjhldfjosBaskdfsA
ababab
BBAAjdhBA
BBBBBBBBJKL
asdlkajsdlkjasBBAAA
ndls2384u09u09sdfnkBBB
AB

ab

The result contains the following strings marked as AB-equal:

false
true
true
true
false
false
false
true
true
true
Some solutions can be seen here.

I would be thrilled to hear from you! Please share your thoughts and ideas with me via email.

Back to Index