- Question 1
Given an integer array, numbers
, count the number of elements that occur more than once.
Examplenumbers = [1, 3, 3, 4, 4, 4]
There are two non-unique elements: 3 and 4.
Function Description
Complete the function countDuplicate
in the editor below.
countDuplicate
has the following parameter(s):
int numbers[n]
: an array of integers
Returns:
int
: an integer that denotes the number of non-unique values in thenumbers
array
Constraints
3 ≤ n ≤ 1000
1 ≤ numbers[i] ≤ 1000
,0 ≤ i < n
Sample Case 0
Sample Input
8
numbers[] size n = 8
numbers = [1, 3, 1, 4, 5, 6, 3, 2]
Sample Output
2
- Question 2
Given a number num
as a string, you can swap two adjacent digits if both digits have the same parity, i.e., both digits are odd or both are even. You can perform this swap operation as many times as needed.
Your task is to find the largest possible number that can be created by applying the swap operation.
Example
Let num = "7596801"
.
- Swap 5 and 9 →
"7956801"
- Swap 7 and 9 →
"9756801"
- Swap 6 and 8 →
"9765801"
The largest value possible is "9758601"
.
Function Description
Complete the function getLargestNumber
in the editor below.
getLargestNumber
has the following parameter:
string num
: a string of digits
Returns:
string
: the largest number that can be created
Constraints
1 ≤ length of num ≤ 10^5
num
consists of digits0-9
only.
Sample Case 0
Sample Input
0082663
Sample Output
"0882663"
我们长期稳定承接各大科技公司如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.
