Cisco Software Engineer I (Full Time) OA

Question

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

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


Question

There is a set of N jars containing chocolates. Some of them may be empty. Determine the maximum number of chocolates Andrew can pick from the jars given that he cannot pick from jars next to each other.

Write an algorithm to find the maximum number of chocolates that can be picked from the jars in such a way that the chocolates are not picked from jars next to each other.

Input
The first line of input consists of an integer numJars, representing the number of jars (N).
The next line consists of N space-separated integers representing the number of chocolates in each jar.

Output
Print the maximum number of chocolates that can be picked from the jars in such a way that the chocolates are not picked from jars next to each other.

Constraints
1 ≤ N ≤ 1000

Example
Input:
6
5 30 99 60 5 10

Output:
139


Question

Jump game. Given an N×M matrix and starting from cell (1,1), her challenge is to hop in an anti-clockwise direction and skip alternate cells. The goal is to find out the last cell she would hop onto.

Write an algorithm to find the last cell Lucy would hop onto after moving anti-clockwise and skipping alternate cells.

Input
The first line of input consists of two integers: matrix_row and matrix_col, representing the number of rows (N) and the number of columns (M) in the matrix, respectively.
The next M lines consist of N space-separated integers representing the elements in each cell of the matrix.

Output
Print an integer representing the last cell Lucy would hop onto after following the given instructions.

Example

Input:
3 3
29 8 37
15 41 3
1 10 14

Output:
41

Explanation
Lucy starts at (1,1) and moves anti-clockwise, skipping alternate cells, ending at the last cell which is 41.


我们长期稳定承接各大科技公司如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.

Leave a Reply

Your email address will not be published. Required fields are marked *