Question: Ruby Programming nthmax(n, a) Description: Returns the nth largest value in the array a or nil if it does not exist. That the largest value

Ruby Programming

nthmax(n, a)

Description: Returns the nth largest value in the array a or nil if it does not exist. That the largest value is specified using n = 0.

Type: (Integer, Array) -> Integer or nil

Assumptions: n is non-negative.

Examples:

nthmax(0, [1,2,3,0]) == 3

nthmax(1, [3,2,1,0]) == 2

nthmax(2, [7,3,4,5]) == 4

nthmax(5, [1,2,3]) == nil

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 Databases Questions!