get max topper marks in array and get roght side topper
function findToppersMarks(arr) {
const n = arr.length;
const toppersMarks = [];
let currentMax = -Infinity;
for (let i = n - 1; i >= 0; i--) {
if (arr[i] > currentMax) {
currentMax = arr[i];
toppersMarks.push(currentMax);
}
}
return toppersMarks.reverse();
}
const result = findToppersMarks(marks);
console.log(result); // Output: [30, 40, 50, 60, 55]