# Amazon Student Programs Software Development Engineer Intern Online Assessment 2024

The online assessment will include a coding assessment (70 mins) and a work style assessment (15 mins). The set time limit will start once you begin the coding assessment.

The Coding Assessment asks you to solve two coding problems and you will have the choice of coding in C, C++, C#, Go, Java, JavaScript, Kotlin, Objective C, Python, Ruby, Scala, or Swift. Next, is the Workstyles Assessment, which is built around Amazon’s Leadership Principles and asks you to choose statements based on your approach to work.

**1. Code Question 1**

Amazon is developing an efficient string matching library. Develop a prototype service that matches a simple pattern with a text. There are two arrays of strings, `text`

and `pat`

, each of size `n`

. Each string in `pat`

is a regex expression that contains exactly one wildcard character (*).

A wildcard character (*) matches any sequence of zero or more lowercase English letters. A regex matches some string if it is possible to replace the wildcard character with some sequence of characters such that the regex expression becomes equal to the string. No other character can be changed. For example, regex “ab*c*bd” matches “abccbd”, “abefgcfbd” and “abccbd” whereas it does not match the strings “abcd”, “abzcbd”, “abccd”, “abcd”.

For every `i`

from 1 to `n`

, your task is to find out whether `pat[i]`

matches `text[i]`

. Return the answer as an array of strings of size `n`

where the `i`

-th string is “YES” if `pat[i]`

matches `text[i]`

, and “NO” otherwise.

Note: The implementation shall not use any in build regex libraries.

Example Given `n = 2`

, `text = ["code", "coder"]`

, `pat = ["co*d", "co*er"]`

,

`text[0]`

= “code”,`pat[0]`

= “co*d”, “NO”, the suffixes do not match`text[1]`

= “coder”,`pat[1]`

= “co*er”, “YES”, the prefixes and suffixes match

Here prefix of a string is defined as any substring that starts at the beginning of the string and suffix of a string is defined as any substring that ends at the end of the string.

Return [“NO”, “YES”].

Function Description Complete the function `matchStrings`

in the editor below.

`matchStrings`

has the following parameters:

`string text[n]`

: the strings to test`string pat[n]`

: the patterns to match

Returns

`string[n]`

: “YES” or “NO” answers to the queries

**2. Code Question 2**

Amazon has several warehouses that store piles of boxes containing goods to be shipped.

In one such warehouse, there are a total of `n`

piles numbered 1, 2, …, `n`

, where the `i`

-th pile has `boxes[i]`

number of boxes. To have an even distribution of boxes, the caretaker can do the following operation any number of times (possibly zero):

- Choose two distinct piles,
`i`

and`j`

(1 ≤`i`

,`j`

≤`n`

), such that`boxes[i]`

> 0. - Remove one box from pile
`i`

and place it on pile`j`

. More formally, increment`boxes[j]`

by 1 and decrement`boxes[i]`

by 1.

For even distribution, the caretaker wishes to minimize the difference between the maximum and the minimum number of boxes in the piles. Call the minimum difference achievable `d`

. The goal is to find the minimum number of operations required to achieve the difference `d`

.

Example

Consider the number of piles to be `n = 4`

and the boxes in them are `boxes = [5, 5, 8, 7]`

. The minimum possible difference that can be achieved is 1 by transforming the piles into [6, 6, 7, 6] as follows:

(Hence, the answer is 2. Note that there are multiple optimal pile configurations such as [6, 6, 7, 6], [6, 6, 6, 7].)

Function Description Complete the function `findMinimumOperations`

in the editor below.

`findMinimumOperations`

has the following parameter:

`int boxes[n]`

: the number of boxes in each pile

Returns

`long int`

: the minimum number of operations to achieve the minimum possible difference

Constraints

`1 ≤ n ≤ 10^5`

`1 ≤ boxes[i] ≤ 10^9`

Input Format For Custom Testing The first line contains an integer, `n`

, the number of elements in `boxes`

. Each line `i`

of the `n`

subsequent lines (where 0 ≤ `i`

< `n`

) contains an integer, `boxes[i]`

.