1. Smallest String
Given a string s
that consists of lowercase English letters, select exactly one non-empty substring of s
and replace each character of it with the previous character of the English alphabet. For example, 'b' is converted to 'a', 'c' is converted to 'b', ..., and 'a' is converted to 'z'.
Find the alphabetically smallest string that can be obtained after performing the above operation exactly once.
Example
s = "hackerrank"
Select New string
h gackerrank
ha gzckerrank
err hackdqqank
Select and change only the first character. Return "gackerrank"
, the alphabetically smallest string possible.
Function Description
Complete the function getSmallestString
in the editor below.
getSmallestString
has the following parameter:
s
: a string
Return
string
: the alphabetically smallest string possible
Constraints
- 1 ≤ length of
s
, |s| ≤ 10⁵
Sample Case 0
Sample Input For Custom Testing
STDIN FUNCTION
----------- ---------------------
"bbcad" string s = "bbcad"
Sample Output
aabad
Explanation
Change bbc
to aab
.

2. Bitwise XOR Subsequences
A subsequence of an array is formed by removing zero or more elements from an array without changing the order of the remaining elements. In a valid subsequence, each pair of adjacent elements of the subsequence has bitwise XOR equal to k
. Note that any subsequence of length 1 is valid regardless of the value of k
, because there is no pair of adjacent elements in such a subsequence.
Given an array of integers and integer k
, determine the length of the longest valid subsequence in the array.
Example
n = 5
arr = [2, 1, 3, 5, 2]
k = 2
The subsequence [1, 3]
is valid because for all pairs of adjacent elements it has (1 and 3), the bitwise XOR of such elements is equal to k
(1 XOR 3 = 2). There are no other valid subsequences that are longer than 2. For example, subsequence [2, 1, 3]
is not valid because 2 XOR 1 does not equal 2.
Function Description
Complete the function maxSubsequenceLength
in the editor below. The function must return the length of the longest valid subsequence of the array, given parameter k
.
maxSubsequenceLength
has the following parameters:
int n
: the size ofarr
int arr[n]
: an array of integersint k
: an integer
Constraints
- 1 ≤ n ≤ 10⁵
- 0 ≤ arr[i] ≤ 10⁶
- 0 ≤ k ≤ 10⁶
Sample Case 0
Sample Input For Custom Testing
STDIN Function
----------- ----------------------------
3 n = 3
0 k = 0
3 arr[] size n = 3
1 1 1 arr = [1, 1, 1]
Sample Output
3
Explanation
The longest valid subsequence is the whole array because every pair of adjacent elements is (1, 1) and 1 XOR 1 = 0.
Sample Case 1
Sample Input For Custom Testing
STDIN Function
----------- ----------------------------
5 n = 5
5 k = 5
5 arr[] size n = 5
1 2 2 1 3 arr = [1, 2, 2, 1, 3]
Sample 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.
