Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple Max Difference Given an array of integers.nums, return the meximum cifference, numsfy) - num . for all pair numai - numai) where icy. Return-1

Simple Max Difference Given an array of integers.nums, return the meximum cifference, numsfy) - num . for all pair numai - numai) where icy. Return-1 if there is not a pair that satisfies this condition For example, given the array nums = 17,1,2,5the largest dittarence is 51 = 4 Function Description Complete the function maxDifference in the editor below. The function must return the maximum difference between two elements as described maxDiference has the following parameters: numis: an array of integers. Constraints Is Ns 102 .-10. mail - 10 Input Format For Custom Testing Lacked stu code reads in out from stdin and passes it to the function The first line contains an integer, n, cenoting the number of elements in the array mums Each of the next lines contains an integer nunsiy Sample Case 0 Sample Input For Custom Testing Sample Output Explanation 70 is the largest number in the array and 1 is the lowest number in the array. However, the index of 10 is ower than the lowest index that contains also the condition of the problem is not satisfied. Using zero-based index notation, the correct answer is a/2 - 0-10-2-8. This sat sfies the condition the larger number in the pair, should be positioned at a higher ndex in the array than the lower number. Sample Case 1 Sample Input For Custom Testing Sample Input For Custom Testing Sample Output Explanation The value of max Difference is 9.7 = 2. 9 occurs at and 7 occurs at all. This satisfies the condtion that the larger number has a higher inclex than the smaller number YOUR ANSWER For help on how to read input and write output in Python 3, click here. Saving draft. View Cada Diff Python 3 I !/bin/python3 + 11 12 Complete the 'maxDifference' function below. 11 15 16 17 The function is expected to return an INTEGER. # The function accepta INTEGER ARRAY nuns as parameter. de maxDifferences ): # Write your code here 22 - it _ame -- maia

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Invoking return the number of the elements in an arraylistx

Answered: 1 week ago