Amazon developers are creating a new security module for Amazon Web Services. One of its functions is to obfuscate incoming messages. The obfuscation method is to select some substring of the message and right rotate that substring by 1 position one time only. The substring is selected in such a way that the resulting obfuscated message is alphabetically the smallest message that can be formed using this operation.
Here, right rotating any string by 1 position is to shift every character of string a
in the right direction by 1 position and remove the last character and append it to the beginning of string a
. For example, a = "ahssd"
, after right rotation by 1 position string a
changes to "dahss"
.
Given the input message as a string, find the obfuscated message.
Note: A string x
is alphabetically smaller than string y
, if either x
is a prefix of y
(and x ≠ y
), or there exists such i
(0 ≤ i
< min(|x
|, |y
|)), that x[i]
< y[i]
, and for any j
(0 ≤ j
< i
) x[j]
= y[j]
. Here, |a
| denotes the length of the string a
.
Function Description
Complete the function findObfuscateMessage
in the editor below.
findObfuscateMessage
has the following parameter:
- string message: the input message
Returns
string
: the encrypted message
Image source will be attached in next update...
Example 1:
Input:
charges = [-2, 4, 3, -2, 1]
Explanation: One way the engineers can remove the system charges is as follows:
Index of the charge removed (0-indexed) | New state of charges |
---|---|
0 | [4, 3, -2, 1] |
2 | [4, 4] |
1 | [4] |
Final charge = 4
.
Output:
4
Example 2:
Input:
charges = [-2, 4, 9, 1, -1]
Explanation: One way the engineers can remove the system charges is as follows:
Index of the charge removed (0-indexed) | New state of charges |
---|---|
0 | [4, 9, 1, -1] |
3 | [4, 9, 1] |
2 | [4, 9] |
0 | [9] |
Final charge = 9
.
Output:
9
Example 3:
Input:
charges = [-1, 3, 2]
Explanation: One way the engineers can remove the system charges is as follows:
Index of the charge removed (0-indexed) | New state of charges |
---|---|
0 | [3, 2] |
1 | [3] |
Final charge = 3
.
Output:
3
我们长期稳定承接各大科技公司如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.