今天石老师给大家分享的 citadel OA限时75分钟,Q1是身份验证的问题,剩余只有2道非常简单的算法题
Question 2
Given a binary sequence of length n
as a string, perform the following operation any number of times:
- Append either a '0' or a '1' to the end of the sequence.
A sequence is considered valid if it is possible to make the total number of "10"
subsequences in the updated sequence exactly equal to k
.
Your task is to count the total number of valid non-empty prefix sequences of the given binary sequence.
Notes:
- A sequence is a subsequence if it can be obtained by deleting digits (possibly none) without altering the relative positions.
- A non-empty prefix sequence is any sequence derived by deleting digits from the end of the given sequence, ensuring the length of the prefix is at least 1.
Example
Given sequence = "100"
, k = 1
Analyze all non-empty prefix sequences:
Prefix Sequence | Appended String | Sequence Formed After Append | Is Good? |
---|---|---|---|
"1" | "01" | "101" | Good (There are k "10" sequences) |
"10" | Blank | "10" | Good (There are k "10" sequences) |
"100" | -- | -- | Not Good (Not possible) |
For "100"
, there are already 2 subsequences of "10"
: indices (0, 1) and indices (0, 2). Hence, the number of non-empty prefix sequences of the given binary sequence is 2.
Return 2
.
Function Description
Complete the function calculateTotalPrefix
in the editor with the following parameters:
string sequence
: the binary sequenceint k
: the number of"10"
subsequences desired
Returns
int
: the total number of non-empty prefix sequences of the given binary sequence
Constraints
- 1 ≤ n ≤ 2 × 10^5
- 1 ≤ k ≤ 10^9
Sample Input 0
101
2
Sample Output 0
2
Explanation
Analyze all non-empty prefix sequences:
Prefix Sequence | Appended String | Sequence Formed After Append | Is Good? |
---|---|---|---|
"1" | "00" | "100" | Good (k = 2 is satisfied) |
"10" | "0" | "100" | Good (k = 2 is satisfied) |
"101" | -- | -- | No (Not possible to make it good) |
For "101"
, there is initially 1 good sequence at indices (0, 1). If a "0"
is appended, there are three good sequences with indices (0, 1), (0, 3), and (1, 3).

Question 3
Devise a strategy to minimize the costs of processing n
images, where each image requires specific filters applied for a defined time frame, and the cost to apply filters to the ith image is filterCost[i]
. Each image must be processed from startDay[i]
to endDay[i]
(inclusive). Additionally, there is an exclusive offer to apply a filter to all n
images at a discounted rate of discountPrice
per day. Your goal is to create an efficient image processing plan that adheres to time constraints and budget considerations, and return the minimum cost modulo (10^9 + 7).
Example
Given n = 3
, filterCost = [2, 3, 4]
, startDay = [1, 1, 2]
, endDay = [2, 3, 4]
and discountPrice = 6
.
Day | Images | Total Cost |
---|---|---|
1 | [1, 2] | 2 + 3 = 5 |
2 | [1, 2, 3] | 2 + 3 + 4 = 9 |
3 | [2, 3] | 3 + 4 = 7 |
4 | [3] | 4 |
Applying filters on all the images at 6 per day on the 2nd and 3rd day will be optimal.
The modulo of the final cost is 5 + 6 + 6 + 4 = 21
.
Function Description
Complete the function getMinProcessingCost
that takes the following parameter(s):
int filterCost[n]
: the cost of filtering each image for processingint startDay[n]
: the first day each image should be processedint endDay[n]
: the last day each image should be processedint discountPrice
: the discounted rate at which filters can be applied to all the images on one day
Returns
int
: the minimum cost to process all the images modulo (10^9 + 7)
Constraints
- 1 ≤ n ≤ 2 × 10^5
- 1 ≤ filterCost[i], startDay[i], endDay[i] ≤ 10^9
- startDay[i] ≤ endDay[i]
- 1 ≤ discountPrice ≤ 10^9
Sample Input For Custom Testing
3
5
3
6
1
4
8
5
5
8
8
Sample Output
37
Explanation
Given n = 3
, filterCost = [5, 3, 6]
, startDay = [1, 4, 8]
, endDay = [5, 5, 8]
and discountPrice = 8
.
Day(s) | Images | Total Cost (per day) |
---|---|---|
1 to 3 | [1] | 5 |
4 to 5 | [1, 2] | 5 + 3 = 8 |
8 | [3] | 6 |
Filter all the images on the 4th and the 5th day at no additional cost.
The modulo of the final cost is 5 * 3 + 8 * 2 + 6 = 37
.

我们长期稳定承接各大科技公司如çitadel、TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We 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.
