leetcode medium problem