normal solution with time complexity n^2