(e,t)=>{let r=[],n=(e,t)=>{Object.keys(e).forEach(i=>{1===t&&r.push(i);let a=t-1;a>0&&n(e[i],a)})};return n(e,t),r}

result

["y","p"]