Replace Elements with Greatest on Right

Easy
Arrays Array

Replace each element with the greatest among elements to its right. Last element becomes -1.

Constraints

1 ≤ len ≤ 10^4

Examples

Example 1:
Input: 17 18 5 4 6 1
Output: 18 6 6 6 1 -1
▲ Console
📱

Install Talent Enrich

Get instant access to jobs and career tools on your device.