Khitan's Solution for LeetCode Problem