# 黑车 新鲜 线上做题

1 Like

1mergingLetters (Task 1 of 4)
Given two strings s and t, your task is to construct a new string consisting of alternate letters from s and t, merged in their original order.
When there are no letters left in one of the strings, append all the remaining letters of the second string to the new string.
For s = “aaaaa” and t = “bbb”, the output should be mergingLetters(s, t) = “abababaa”.
For s = “ab” and t = “abcdef”, the output should be mergingLetters(s, t) = “aabbcdef”.

• [execution time limit] 3 seconds (java)
• [input] string s
A string consisting of lowercase English letters.
Guaranteed constraints:
1 ≤ s.length ≤ 100.
• [input] string t
A string consisting of lowercase English letters.
Guaranteed constraints:
1 ≤ t.length ≤ 100.
• [output] string
The resulting string after merging s and t.

2 You are given a string str containing only the letters W, D, and L. Your task is to construct a new string from the characters of str, according to the following algorithm:

1. Begin with an empty string output = “”.
2. If str contains a W, then remove it and concatenate a W to the end of output.
3. If str contains a D, then remove it and concatenate a D to the end of output.
4. If str contains an L, then remove it and concatenate an L to the end of output.
5. If str is empty, end the algorithm; otherwise go back to step 2.

Return the value of output after the algorithm is complete.

Note that it doesn’t matter from where you remove the letter from the string, only the count of the letters left in the string matters.

Example

• For str = “LDWDL”, the output should be equallyRearranging(str) = “WDLDL”.
• str contains all W, D, and L, so we add them to the output and remove from the initial string one by one and get “WDL”
• The remaining string contains only letters D and L, so we add them to the output and get “WDLDL” as the answer

3 you are given a 2 dimentional square matrix m and an interger k, your task is to rotate the given matrix over diagonals k times and return the resulting matrix

4You are given an array of integers arr. Your task is to count the number of contiguous subarrays, such that each element of the subarray appears at least twice.

Example

• For arr = [0, 0, 0], the output should be duplicatesOnSegment(arr) = 3.
There are 3 subarrays that satisfy the criteria of containing only duplicate elements:
• arr[0…1] = [0, 0]
• arr[1…2] = [0, 0]
• arr[0…2] = [0, 0, 0]
• For arr = [1, 2, 1, 2, 3], the output should be duplicatesOnSegment(arr) = 1.
There is only 1 applicable subarray: arr[0…3] = [1, 2, 1, 2].

Input/Output

• [execution time limit] 3 seconds (java)
• [input] array.integer arr
An array of integers.
Guaranteed constraints:
3 arr.length 103,
0 arr[i] 104.
• [output] integer
Return the number of contiguous subarrays in which each element occurs at least twice