Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
948 views
in Online Assessments by Expert (46,090 points) | 948 views

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 (46,090 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*