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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started