Today I had my OA round of amazon it had 2 Coding Questions ( 90 min ).

  1. Min number of iterations to sort an array. You can only move by one position.
  2. max number of subarrays where left and right index positions difference is less or equal than k
    k = 3 array=[1, 3 , 5]

explanation: for index (0,0) the difference is diff = {abs(1 - 1)}, diff < k so that is the first subarray.
for index (0,1) the difference is diff = {abs(1 - 3)}, diff < k so that is the second subarray.
for index (1,1) the difference is diff = {abs(3 - 3)}, diff < k so that is the third subarray.
for index (1,2) the difference is diff = {abs(3 - 5)}, diff < k so that is the fourth subarray.
for index (2,2) the difference is diff = {abs(5 - 5)}, diff < k so that is the fifth subarray.
But for index (0,2) the difference is diff = {abs(1 - 5)}, diff > k so that is NOT a subarray.

The total amount of subarray is 5

Comments (5)