1. Question 1
Given a string s
of lowercase English characters, the following operation can be performed any number of times:
Choose three consecutive characters s[i]
, s[i+1]
, and s[i+2]
where (1 ≤ i ≤ |s| - 2, 1-based indexing) such that s[i] == s[i+1]
and s[i+1] != s[i+2]
. Replace s[i+2]
with s[i]
.
Find the maximum number of operations that can be applied to s
.
Example
s = "accept"
:
The following operations are performed (bold indicates changed character):
- Start at
i = 2
,"cce"
: The new strings′ = "acccpt"
- Start at
i = 3
,s′ = "acccct"
- Start at
i = 4
,s′ = "accccc"
No other selections are available. The operation can be applied a maximum of 3 times.
Function Description
Complete the function getMaximumOperations
in the editor with the following parameters:
string s
: the string to transform
Returns
long_int
: the maximum number of times the operation can be applied
Constraints
- 3 ≤ length of
s
≤ 2 × 10⁵ - The string
s
only contains lowercase English letters

2. Question 2
Implement a session-based authentication system that manages user sessions with unique tokens and configurable time-to-live (TTL) values. Each token has an expiration time calculated by adding the TTL (in seconds) to the creation time. Tokens can be renewed before expiration to extend their validity. The system must support these three operations:
generate <token_id> <current_time>
:
At the current time, creates a new token with the specified ID.renew <token_id> <current_time>
:
At the current time, extends an existing, unexpired token’s expiration time. The request is ignored if the token has expired or does not exist.count <current_time>
:
Returns the number of unexpired tokens at the current time.
Important Note: Token expiration is evaluated before processing any actions at the same timestamp. If a token’s expiration time exactly matches the current time, the token is considered expired and cannot be renewed or counted.
Example
Suppose time_to_live = 5
, andqueries = ["generate aaa 1", "renew aaa 2", "count 6", "generate bbb 7", "renew aaa 8", "renew bbb 10", "count 15"]
.
The output of the system is [1, 0]
.
At t = 6
, the only unexpired token is "aaa"
. At t = 15
, all tokens have expired, so the count of unexpired tokens is 0
.
Function Description
Complete the function getUnexpiredTokens
in the editor with the following parameter(s):
int time_to_live
: the time to live for a tokenstring queries[q]
: the queries
Returns
int[]
: the results of thecount
queries, in the same order as they appear
Constraints
- 1 ≤
q
≤ 100000 - 1 ≤
|queries|
≤ 10⁵ - 1 ≤
time_to_live
≤ 10⁸ - 1 ≤
current_time
≤ 10⁸ - 1 ≤ length of
token_id
≤ 10 token_id
consists only of lowercase letters and numbers- All queries of type
generate
will contain unique values oftoken_id
current_time
is in non-decreasing order in the queries

我们长期稳定承接各大科技公司如微软、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.
