Amazon OA SDE 2
Anonymous User
1631

Question1 :-

Assume customers have participated in tournament having "initialScores" given in an array.

They will participate in last tournament where the winner of last tounament will get additional 'n' points, runner will get 'n - 1' and so on up until '1' point to last customer.

How many customers are there such that if they win in last tournament, they will get highest score?

Example:


initialScores = [1, 3, 4], n = 3

If customer 0 wins, his finalScore = 1 + 3 = 4, then if runner is customer 2, his finalScore = 4 + 2 = 6. 
So even if customer 0 wins, he doesn't have highest score. So do not count it

If customer 1 wins, his finalScore = 3 + 3 = 6 and if runner is customer 2, his finalScore = 4 + 2 = 6. So customer 1 has highest score if he wins
count = 1

If customer 2 wins, his finalScore = 4 + 3 = 7, assume if runner is customer 1, his finalScore = 3 + 2 = 5. So customer 2 has highest score if he wins
count = 2

ans: 2

Question 2:-

Vulnerability factor is defined as the maximum length of subarray that has gcd > 1

Given 'arr' and 'k', find least possible vulnerability of the given 'arr' after making atmost 'k' changes. You can update any value in the array per change.

Example 1:

[2, 2, 4, 9, 6] k = 1

possible changes are:
1. change first element to 3 [3, 2, 4, 9, 6]. The length of longest subarray with GCD>1 is 2. [2,4] and [9,6]
2. change third element to 5 [2, 3, 5, 9, 6]. In this case, the length of longest subarray with GCD>1 is 2. [2, 2] and [9, 6]

Since no operation can reduce the maximum length of any subarray with GCD>1 to less than 2, ans is 2

Example 2:

[5, 10, 20, 10, 15, 5] k = 2
ans: 2

possible changes are:
1. [5, 10, 2, 3, 15, 5] maxLength = 2 for [5,10][10,2][3,15][15,5]
2. [7, 10, 20, 9, 15, 5] maxLength = 2 for [10,20][9,15][15,5]

So least possible maxLength = 2, hence ans = 2

Example 3:

[4, 2, 4] k = 1
ans: 1

If you change to [4, 3, 4], subarrays with GCD> 1 are [4][3][4], so maxLength = 1

So least possible maxLength = 1, hence ans = 1

constraints:
1 <= n <= 10^5
0 <= k <= n
1 <= list[i] <= 10^9

Comments (11)