Don’t use string logic for this.
Parse the string into a BitSet
, before entering your loops, i.e. as you read them.
Then use methods or(BitSet set)
, and cardinality()
.
I just completed challenge doing that. No timeouts.
2
solved I am facing timeout for my solution for a HackerRank