Oracle OA | On Campus
Anonymous User
2705

Oracle's OnA had 22 questions. Two DSA questions. Ten Aptitude and ten questions on english.
The two dsa questions were:
Q1) Throw The Ball
In a park, there are n friends standing in a random order, and they plan to throw a ball around. Each friend has a unique number in the range of 1 to n, inclusive. The ith friend will always throw the ball towards the friend given at receiver[i], and this will happen each second. Friend 1 always starts with the ball, and a player always throws to another player. Determine which friend has the ball after k seconds pass.
Note: Friends are numbered starting with 1.
Example
receiver=[2,4,1,5,3]
seconds=6

SendorReciverTime
121
242
453
534
315
126
After 6 seconds, the ball will be with friend 2.
Function Description
int receiver[n]: the ith friend will throw the ball to the friend indicated in receiver
long seconds: The time in seconds that the game lasts
Constraints:
1< size of receiver < 10^5
receiver[i]!=i
1<seconds<10^12
Test Cases
Input Test Case 1
Input:
[6,5,2,5,3,2], 7
Output:
3
Test Case 2:
Input:
[3,1,4,2], 6
Output:
3
Q2)Frequency of Maximum Value
Given an array ‘nums’ of length N containing positive integers and an array ‘query’ of length ‘Q’ containing indexes, print/store for each query the count of maximum value in the sub-array starting at index ‘i’ and ending at index ‘N-1’.

For eg:- nums = [ 5, 4, 5, 3, 2 ] and q = [ 1, 2, 3, 4, 5 ]

Answer would be [ 2, 1, 1, 1, 1 ].

For the first query, we have to find the count of maximum value( which is 5) in the subarray [ 5, 4, 5, 3,2 ], which is 2.

For the second query, the count of maximum value(which is 5) in the subarray [4, 5, 3, 2 ], which is 1.

Similarly, for the fourth query, the count of maximum value(which is 3) in the subarray [ 3, 2 ].

Note that the index given in the query array is 1-based indexing.
Constraints:
1<nums.size(),q.size()<10^5
1<nums[i]<10^6
1<q[i]<nums.size()
Test Case:
Input:
nums = [ 5, 4, 5, 3, 2 ] ,q = [ 1, 2, 3, 4, 5 ]
Output:
[ 2, 1, 1, 1, 1 ].

Comments (26)