Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
1,952 views
in Online Assessments by Expert (44,360 points)

1 Answer

0 like 0 dislike

1. Maximum difference between 2 numbers in a list

The question had a list as an input ([3, 6, 10, 1, 4, 6, 5], for example)
You have to design an algorithm that finds the greatest difference between two elements, such that the larger element appears after the smaller element.
In the example above, the output should be 7 (10-3 = 7).

Return -1 if the maximum difference is flat or negative.

Constraints I remember:
1 =< size of array

 

by Expert (44,360 points)
0 0
use suffix max array to compute max difference
*can easily be solved in O(n) time and space
*I doubt whether a problem this easy is asked in apple oa*
...