Question
1001.
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.
Examples
Example 1:
Input:
7
2 3 10 6 4 8 1
Output
8
Explanation
From 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:
Input:
3
4 3 1
Output
0
Explanation:
In the given list there is no larger element after the smaller element.
So, the output is 0.
Question
The first line of input consists of an integer N (1 ≤ N ≤ 1000), size representing the number of entries in the array (N).
The next line consists of N space-separated integer elements in the array.
Output
Print the smallest value of the person who is not a twin from the given array of elements.
Note
If everyone present is a twin, then return -1.
Examples
Example 1:
Input:
7
1 1 2 3 3 4 4
Output:
2
Explanation:
In the given array of elements, the only non-twin element is 2.
So, the output is 2.
Example 2:
Input:
4
1 1 2 2
Output:
-1
Explanation:
The given array of elements contains all twin elements.
So, the output is -1.
CISCO
The current selected programming language is Python3. We emphasize the submission of a fully working code over partially correct but efficient code. Use of certain header files are restricted. Once submitted, you cannot review this problem again. You can use print to debug your code. The print may not work in case of syntax/runtime error. The version of Python being used is 3.5.2.
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.
Examples
Example 1:
Input:
7
2 3 10 6 4 8 1
Output:
8
Example 2:
Input:
3
4 3 1
Output:
0
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
