Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Let’s answer the queries offline.
Start from the <b>last</b> query until you reach the first query.
Each time, append the value of that query to a <code>ans</code> array if it wasn’t already appended.
Then start from the <b>beginning</b> of <code>windows</code> and append to <code>ans</code> array if it wasn’t already appended.