convert getAllCombinations from array merging approach to bitwise construction