- Maximum Likes
You are a TikTok content creator with predictions about which trends will be popular over the next n
days. These trends are represented by an array prediction
, where the trend that will be popular on the i
ᵗʰ day is given by prediction[i]
.
Before the trends gain popularity, you need to select a set of trends to focus on. For each trend x
that you choose, you will earn x
likes every time that trend appears in the prediction
array. However, to maintain diversity in your content, if you choose the x
-th trend, you cannot choose the (x - 1)
ᵗʰ or (x + 1)
ᵗʰ trends, as they are considered too similar.
Your objective is to maximize the total number of likes you can earn by carefully selecting which trends to focus on. Since the total number of likes can be large, return your answer modulo 10⁹ + 7
.
Example
Suppose n = 3
, prediction = [1, 3, 2]
Choose trends 1
and 3
. You will get 1
like on the first day and 3
likes on the second day.
Hence the answer is 4
.
Function Description
Complete the function maximumLikes
in the editor below.
getMaxScore
has the following parameter(s):
int prediction[n]
: an array of integers
Returns
int
: the maximum possible likes modulo10⁹ + 7
Constraints
1 ≤ n ≤ 10⁵
1 ≤ prediction[i] ≤ 10⁹
Sample Case 0
Input:
2
1
3
Output:
4
Explanation:
Choose trends 1
and 3
. You will get 0
likes on the first day, 1
like on the second day, and 3
likes on the third day.
Sample Case 1
Input:
7
1 2 3 3 3 4 4
Output:
10
- Match and Swipe
Several TikTok creators are participating in a trending challenge called Match-and-Swipe. There are k
creators, labeled from 1
to k
, and they start with a shared video sequence represented by the string videoSequence
.
Here's how the challenge works: each creator takes turns (creator 1
goes first, followed by creator 2
, and so on, cycling back to creator 1
after creator k
’s turn). On each turn, a creator can remove any two consecutive matching clips (represented by matching letters in videoSequence
) and merge the remaining parts of the sequence back together.
The game continues until there are no consecutive matching clips left. If a creator cannot make a move, they lose, and the challenge ends. Given that all creators play strategically, determine the number of the creator who will lose.
Example
Given, videoSequence = "pzwoowz"
and k = 3
Creator | videoSequence |
---|---|
1 | pzwoowz |
2 | pzwz |
3 | pzz |
1 | p |
On each turn, the creator selects the highlighted pair. Creator 1
loses when there are no valid pairs left to remove.
Return 1
.
Function Description
Complete the function findLoser
in the editor below.
findLoser
takes the following parameters:
string videoSequence
: the shared video sequenceint k
: the number of creators participating in Match and Swipe challenge
Returns
int
: the creator who is unable to make a move on their turn
Constraints
1 ≤ |videoSequence| ≤ 10⁵
1 ≤ k ≤ 10⁵
我们长期稳定承接各大科技公司如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.
