Question 1: Inventory Management System
Amazon's software developers are working on enhancing their inventory management system with a new feature. The goal is to analyze an array of n
products, where the price of the i-th
product is given by prod_price[i]
. The objective is to determine the minimum number of price adjustments needed to ensure that the Amazon pricing algorithm yields the same price for the sums of all subarrays of length k
within the array prod_price
.
Price adjustment operations can be performed as follows:
- Modify any number of values in the array
prod_price[i]
to any positive integer.
Given the array prod_price
and a positive integer k
, find the minimum number of changes required so that the sum of elements in all subarrays of length k
is equal.
Note:
- A subarray is a contiguous segment of an array.
Example: Given,
n = 4, prod_price = [5, 7, 7, 8], k = 2
Output:
The minimum number of changes required is 1.
Question 2: Array Generator Service
Your project team needs to work closely with a group of software testers. They have requested that your team create an array generator service to assist with testing software functionality.
Its input parameters are:
arr[n]
: containsn
positive integers.state
: is a string that containsn
characters.- Each character is a '0' or '1'.
- If
state[i]='1'
,arr[i]
is available. - If
state[i]='0'
,arr[i]
is blocked.
To create an integer array S
, the following operation is performed exactly m
times. S
is initially empty:
- Choose any
arr[i]
that is available, that is, wherestate[i]='1'
, the same element can be chosen any number of times. - Append the value in
arr[i]
toS
. - For all
state[i]='0'
such thatstate[i-1]='1'
, changestate[i]
to '1'. For example, ifstate = '0100101'
before the operation, it equals0110111
after the operation.
Find the lexicographically largest sequence S
that can be obtained after m
operations.
Note:
- A sequence
x
of lengthm
is lexicographically larger than sequencey
of lengthm
if there exists suchi (0 <= i < m)
, thatx[i] > y[i]
, and for anyj (0 <= j < i)
,x[j] = y[j]
.
Example: Input:
arr = [4, 5, 6, 3], state = "1100", m = 5
Output:
The lexicographically largest sequence is [6, 5, 5, 4, 4].
CSOAhelp长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
CSOAhelp consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.