Finding strings with equal number of 'A's and 'B's

Published:
October 24, 2022

Given a number of strings that contains random ASCII characters, find all strings, that contain the same amount of ‘A’ and ‘B’ characters.

We call strings that fulfill this criterium AB-equal.

Some examples:

ABABABjhkdsgisfgjoBBAABBA
BBAAaslkjhdlkajlkasjdlkjhldfjosBaskdfsA
ababab
BBAAjdhBA
BBBBBBBBJKL
asdlkajsdlkjasBBAAA
ndls2384u09u09sdfnkBBB
AB

ab

This should result in the following strings being identified 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