optimized algo2 further, still need to fix quickSolution