Question: Please Give solution in JAVA Write a function named is Olympic that returns 1 if its array argument is an Olympic array otherwise it should

Please Give solution in JAVA

Write a function named is Olympic that returns 1 if its array argument is an Olympic array otherwise it should return 0

An olympic array is defined to be an array in which every value us greater than or equal to the sum of the values less than it. The sum of the values less than the minimum value in the array is defined to be 0, for example {3,2,1} is an olympic array because

(A) 1 is the minimum value and by definition the sum of the values less than it is 0, since 1 is greater than 0 it satisfies the condition.

(B) There is only one value less than 2 and 2 are less than 3 and 3 is equal to their sum, so the value satisifes the condition.

(C) The values 1 and 2 are less than 3 and 3 is equal to their sum, so the value 3 satisifes the condition.

Hence all elements of the array satisfy the condition and the array is an Olympic array.

Example: {2,2,1,1} is also an olympic array, because the values less than 2 sum to 2

{1,1000,100,10000, 2 } is also an oympic array,

However {1,99,99, 1000,100, 10000,2} is not an olympic array because the sum of the numbers less than 100(99 +99+ 1) is greater than 100

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!