divide and conquer solution