educative.io

Would bit-wise operation work?

Hi,

I’m wondering if we can solve this problem using the bitwise operator XOR ^. Since ^ produces a zero if two bits are the same, for combinations “abc” and “bca”, ‘a’^‘b’^‘c’^’^‘b’^‘c’^‘a’ would be zero. Can we use this property to check if a combination is present?

Thank you so much.

You can apply bitwise operator to solve your problem but we find an optimal solution with the help of HashMap.