add recursive impl, though with TLE(Time Limit Exceeded)