Question: Assume function genPerm ( n: number ) : number [ ] creates a random permutation of the numbers 0 . . n - 1 .

Assume function genPerm(n: number): number[] creates a random permutation of the numbers 0.. n-1.
Given the code:
function rotate(a: number[]): number[]{
if (a.length >0) a.push(a.shift() as number); // removes first element, shifts others by one to front, adds element at end
return a;
}
function genInput(n: number): number[][]{
const m: number[][]=[];
let a = genPerm(n); // generates random permutation
for (let i = n; --i >=0;) m.push(rotate(a));
return m;
}
const m = genInput(5);
If we now sum each column of m, what is the largest sum?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!