I have this data:

There are three columns r_code, wtg_code and rr. Every row can be treated as a collection of object properties. We have to select n number of rows from the existing rows. Considering the row are sorted in decreasing order of r_code, constraints are,
If you can give the solution in Javascript then it will be better otherwise I welcome any language.
In JavaScript, the data can be represented like this:
let data = [
{ r_code: 5, wtg_code: 8, rr: 3.4 },
{ r_code: 5, wtg_code: 8, rr: 3.4 },
{ r_code: 5, wtg_code: 7, rr: 4.5 },
{ r_code: 4, wtg_code: 6, rr: 1.2 },
{ r_code: 4, wtg_code: 6, rr: 2.4 },
{ r_code: 4, wtg_code: 6, rr: 4.5 },
{ r_code: 2, wtg_code: 6, rr: 1.6 },
{ r_code: 2, wtg_code: 5, rr: 7.4 },
{ r_code: 1, wtg_code: 4, rr: 3.1 },
{ r_code: 1, wtg_code: 4, rr: 2.9 },
{ r_code: 1, wtg_code: 3, rr: 3.3 },
];
Considering the row are sorted in decreasing order of r_code
That could still allow for several permutations. The rules for selection really mean that you should sort the data more precisely: by descending r_code, descending wtg_code and ascending wtg_code.
For that you can use the sort method.
data.sort((a, b) => b.r_code - a.r_code || b.wtg_code - a.wtg_code || a.rr - b.rr);
Finally, if you are interested in the first 10 (n=10), then slice:
let n = 10;
console.log(data.slice(0, n));