Microsoft interview question

DSA related problems. Medium level.