Panda Guru LogoPanda
Guru

Amazon OA

Round 1

Questions:

Question 1

Problem: Rate-Limiting Algorithm

Some developers at Amazon are building a prototype for a simple rate-limiting algorithm. There are n requests to be processed by the server, represented by a string requests, where the i-th character represents the region of the i-th client. Each request takes 1 unit of time to process.

There must be a minimum time gap of minGap units between any two requests from the same region.

Example 1:

Suppose n = 6, requests = "aaabbb", and minGap = 2:

requests: a a a b b b | | | | ab _ ab _ ab (minimum time gap of 2 between same region requests)

The requests can be sent in the order ab_ab_ab where _ represents that no request was sent in that unit time. Here, the minimum time gap between two requests from the same region is minGap = 2.

The total time taken is 8 units.

Example 2:

Input:

12 abacadaeafag 2

Explanation:

Sample Output:

16

Explanation: One optimal strategy is: "ab_ad_afgae_ac_a"

Function Description:

Complete the function getMinTime in the editor below:

def getMinTime(n: int, requests: str, minGap: int) -> int:

Parameters:

Returns:

Question 2

Problem: Lexicographically Smallest Special String

Developers at Amazon are working on a text generation utility for one of their new products.

Currently, the utility generates only special strings. A string is special if there are no matching adjacent characters. Given a string s of length n, generate a special string of length n that is lexicographically greater than s. If multiple such special strings are possible, then return the lexicographically smallest string among them.

Notes:

A string a is lexicographically smaller than a string b if and only if one of the following holds:

Important Considerations:

Example:

Suppose s = "abbd":

Some of the special strings that are lexicographically greater than s are shown below:

abbd -> abca

The lexicographically smallest special string that is greater than "abbd" is "abca".

Function Description:

Complete the function getSpecialString in the editor below:

def getSpecialString(n: int, s: str) -> str:

Parameters:

Returns: