The original solution uses additional <queue> which violates constant space requirement.