Question: Amazon, Recent Online Assessment(OA) Questions | Max Stock Increase & Median Subsequences | 28th Feb 2026 | Hackerrank
0
Entering edit mode

Question 1: Max and Min Median of Subsequences

Problem Statement:

Given an array values of size n and an integer k, find the maximum and minimum possible medians among all possible subsequences of length k.

Return an array of two integers containing the maximum median followed by the minimum median.

(Note: Since we are evaluating subsequences, the order of elements picked from the original array does not matter, which means we can optimize our selection by sorting the array first.)

Example:

n = 2

values = [56, 21]

k = 1

Subsequences of length 1: [56] (median is 56) and [21] (median is 21).

The maximum median present is 56 and the minimum median present is 21.

Output: [56, 21]

Question 2: Maximum Stock Increase (Max Subarray Sum of Length  K)

Problem Statement:

Amazon warehouse tracks the daily stock changes of a popular product. You are given an array stockChange of length n, where stockChange[i] is the net change in inventory on the ith day (positive \rightarrow stock added, negative \rightarrow stock removed).

Your task is to determine the maximum net increase in stock over any contiguous period of at most k days. If no positive increase is possible, then the answer is 0.

Example:

n = 6

stockChange = [-3, 4, 3, -2, 2, 5]

k = 4

The optimal contiguous period is [3, -2, 2, 5] with a net change of 3 + (-2) + 2 + 5 = 8.

While the period [4, 3, -2, 2, 5] has a net change of 12, its length (5) exceeds the constraint k = 4.

Output: 8

ADD COMMENTlink 12 hours ago Rohit • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts