Improve 340 by using bitset data structure

Used more advance bitset data structure.