Problem Β· Array
Find Maximum Difference
Learn this problemProblem statement
Given a list of integers, find the maximum difference of two elements where the larger number appears after the smaller number.
Write an algorithm to find the maximum difference of two elements where the larger number appears after the smaller number.
Input
The first line of input consists of an integer - inputArray_size, representing the size of the list (N).
The next line consists of N space-separated integers representing the elements of the list.
Output
Print an integer representing the maximum difference of the two elements where the larger number appears after the smaller number. If no such elements are found, print 0.
Function
findMaximumDifference(n: int, inputArray: List<Integer>) β intExamples
Example 1
n = 7inputArray = [2, 3, 10, 6, 4, 8, 1]return = 8From the given list, the maximum difference will be 8 (difference between 2 and 10 :), we won't consider (10 and 1), as the larger number should appear after the smaller one. So, the output is 8 π»
Example 2
n = 3inputArray = [4, 3, 1]return = 0Will add once find reliable source :) Just like what we did for the example 1 above π See yall next time!
More Cisco problems
- Collect CoinsSeen Jun 2025
- FizzBuzz ProblemSeen May 2025
- Find Largest Sum Contiguous SubarraySeen May 2025
- Find Largest Sum of Continuous SequenceSeen May 2025
- Find Palindrome Sub-stringSeen May 2025
- Count Numbers with Digit SumSeen Mar 2025
- Maximum Chocolates from Jars (L.C. 198 :)Seen Mar 2025
- Find Elements Largest in Row Smallest in ColumnSeen Mar 2025