you wanted small time complexity, I give you O/(1) against O/(k^2) space complexity