Recently, I completed an online test (OA) for TSMC OA, and I'd like to share it with you!

TSMC OA Topic I
For string s and integer k, the selection of a substring is valid if the following conditions are satisfied:
- The length of each substring is greater than or equal to k. The length of each substring is equal to k.
- Each sub-string is a palindrome.
- No two substrings overlap.
- Determine the maximum number of valid sub-strings that s can form.
Notes
A substring is a group of neighboring characters in a string.
A palindrome is a string of words that reads the same backwards and forwards.
Example:
text copy edit s = "aababaabce"
k = 3
For this example, some possible choices for non-overlapping palindromic substrings of length at least k are "ababa" and "abce", "aba" and "baab", and the maximum number of such valid substrings is 2.
Functional Description
Use the following parameters to complete the getMaxSubstring function:
- string s: the given string.
- int k: minimum length of valid substring.
return value
- int: the maximum number of valid substrings that can be formed.
Python Code
def getMaxSubstrings(s, k).
n = len(s)
# Step 1: Use DP to identify all echo substrings
dp = [[False] * n for _ in range(n)]
# Every character element is a palindrome
for i in range(n):
dp[i][i] = True
# Check the length of the message for 2.
for i in range(n - 1):
if s[i] == s[i + 1].
dp[i][i + 1] = True
# Checks messages with length greater than 2.
for length in range(3, n + 1):
for i in range(n - length + 1):
j = i + length - 1
if s[i] == s[j] and dp[i + 1][j - 1].
dp[i][j] = True
# Step 2: Filter Substrings by Length
palindromic_substrings = []
for i in range(n):
for j in range(i + k - 1, n):
if dp[i][j].
palindromic_substrings.append((i, j))
# Step 3: Select Non-overlapping Echo Substring
palindromic_substrings.sort(key=lambda x: x[1]) # Sort by the end index
max_count = 0
last_end = -1
for start, end in palindromic_substrings: for start, end in palindromic_substrings: for start, end in palindromic_substrings
if start > last_end.
max_count += 1
last_end = end
return max_count
# Example Usage
s = "aababaabce"
k = 3
print(getMaxSubstrings(s, k)) # Output: 2
TSMC OA Title II
In a coding competition organized to hire software developers, there is an interesting problem involving the Bitwise-OR operation.
The goodness of a sequence is defined as the bitwise OR of its elements. Given an array arr
of length n
The return array should be sorted in non-decreasing order, and you are required to find all possible distinct values of goodness that can be obtained by choosing any strictly increasing subsequence of the array. return array should be sorted in non-decreasing order.
Notes
- A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.
- A strictly increasing subsequence is a subsequence where each element is greater than the previous one.
- The goodness of a sequence is defined as the bitwise OR of all its elements.
(for) instance
Consider n = 4
and arr = [4, 2, 4, 1]
.
The strictly increasing subsequences which can be chosen to have distinct goodness values are.
- Empty subsequence; goodness = 0
[1]
goodness = 1[2]
goodness = 2[4]
goodness = 4[2,4]
goodness = 6
There are no other strictly increasing subsequences that yield a different goodness value. Thus, the answer is [0, 1, 2, 4, 6]
.
Python Code
def findDistinctGoodnessValues(arr).
n = len(arr)
# goodness_values: a collection storing all the different goodness values.
goodness_values = set()
dp = [set() for _ in range(n)]
# For each element arr[i], iteratively count all preceding elements arr[j], where arr[j]<arr[i]
# For each merit value in dp[j], calculate the new merit value by performing a per-bit OR with arr[i] and add it to new_values
# Add arr[i] itself to new_values to interpret subsequences consisting only of arr[i]
for i in range(n):
new_values = set()
for j in range(i):
if arr[j] < arr[i].
for val in dp[j].
new_values.add(val | arr[i])
new_values.add(arr[i])
dp[i] = new_values
# After updating dp[i], add all values in new_values to the goodness_values set
for val in new_values:
goodness_values.add(val)
# Add 0 to the set to include the optimality value of the empty subsequence
goodness_values.add(0)
return sorted(goodness_values)
# Example Usage
arr = [4, 2, 4, 1]
result = findDistinctGoodnessValues(arr)
print(result) # Output: [0, 1, 2, 4, 6]
Learn More
- Tsmc one acre and three quarters
- About TSMC
- TSMC Interview Lazy Person's Kit: Interview Process, Interview Questions
Contact Us
Finally, after our strongInterview AssistanceBy analyzing and communicating with TSMC hackerrank, the interviewer not only understood the candidate's programming ability, but also saw my clear thinking and effective communication skills in solving problems. These not only help us to cope with TSMC's interviews, but also enhance our ability to solve real-world programming problems. I wish you all good luck for the interview!
With our strong interview assistance and OA ghostwriting, the candidate not only understood their programming skills through the analysis and communication of these interview questions, but also saw my clear thinking and effective communication skills in problem-solving. With our strong interview assistance and OA ghostwriting, the candidate not only understood their programming skills through the analysis and communication of these interview questions, but also saw my clear thinking and effective communication skills in problem-solving. These not only help These not only help us cope with TSMC interviews, but also enhance our ability to solve practical programming problems.
If you also need our TSMC hackerrank cheat service and interview assistance service, pleaseContact Us Now.