Modify the String
Given a string input_str
of length n
, choose any character that occurs at least twice and delete any one occurrence. Repeat this until all remaining characters are distinct. Return the lexicographically maximum string that can be formed this way.
Example
input_str = "aabcb"
The length of the string, n = 5
. Some of the strings that can be formed are:
"acb"
– delete the first occurrences of'a'
and'b'
"abc"
– delete the first occurrence of'a'
and the second occurrence of'b'
It can be proven that the lexicographically maximum string that can be obtained is "acb"
.
Function Description
Complete the function getString
in the editor below.
getString
has the following parameters:
string input_str
: a string of lengthn
Returns
string
: the result of the operations, as described
Constraints
input_str
contains only lowercase English letters1 ≤ n ≤ 10^5
Count Binary Substrings
A binary string is a string consisting only of 0s and 1s. A substring is a contiguous group of characters within a string.
Given a binary string, find the number of substrings that contain an equal number of 0s and 1s and all the 0s and 1s are grouped together. Note that duplicate substrings are also counted in the answer. For example, "0011"
has two overlapping substrings that meet the criteria: "0011"
and "01"
.
Example
s = "011001"
The substrings "01"
, "10"
, "1100"
, and "01"
have equal numbers of 0s and 1s with all 0s and 1s grouped consecutively. Hence, the answer is 4. Note that the substring "0110"
has an equal number of 0s and 1s but is not counted because not all 0s and 1s are grouped together.
Function Description
Complete the function getSubstringCount
in the editor below.
getSubstringCount
has the following parameter(s):
s
: a binary string
Returns
int
: the number of substrings that meet the criteria
Constraints
1 ≤ length of s ≤ 10^5
- The string
s
consists of 0s and 1s only
我们长期稳定承接各大科技公司如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.
