Iterative approach (stack based) to solve string wordbreak and 8 queen in JavaScript