naive implementation n^2
using bitset in O(n)