I recently completed a real question for the Online Assessment (OA) to TSMC OA, and I'd like to share it with you~ If you are preparing for TSMC's Online Assessment, first of all, you need to be psychologically prepared: the questions cover a wide range of topics, ranging from basic program design, data processing to logical reasoning. Compared to other tech companies, TSMC emphasizes candidates' engineering thinking and practical problem-solving skills, so it's not enough to just brush up on the questions; you need to understand the nature of the questions and how to solve them efficiently. When I was doing OA myself, I found that it is very important to plan your time wisely and grasp the key points of each question, otherwise it is easy to waste too much energy on the details.

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)
# 步驟1:使用DP識別所有回文子串
dp = [[False] * n for _ in range(n)]
# 每個字元都是回文
for i in range(n):
dp[i][i] = True
# 檢查長度為2的回文
for i in range(n - 1):
if s[i] == s[i + 1]:
dp[i][i + 1] = True
# 檢查長度大於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
# 步驟2:按長度過濾子字串
palindromic_substrings = []
for i in range(n):
for j in range(i + k - 1, n):
if dp[i][j]:
palindromic_substrings.append((i, j))
# 步驟3:選擇非重疊回文子串
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:
if start > last_end:
max_count += 1
last_end = end
return max_count
# 示例用法
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 NThe 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:一個存儲所有不同善良值的集合。
goodness_values = set()
dp = [set() for _ in range(n)]
# 對於每個元素arr[i],反覆運算所有前面的元素arr[j],其中arr[j]<arr[i]
# 對於dp[j]中的每個優度值,通過用arr[i]執行按比特OR來計算新的優度值並將其添加到new_values中
# 將arr[i]本身添加到new_values中,以解釋僅由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
# 更新dp[i]後,將new_values中的所有值添加到goodness_values集合中
for val in new_values:
goodness_values.add(val)
# 將0添加到集合中,以包含空子序列的優度值
goodness_values.add(0)
return sorted(goodness_values)
# 示例用法
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.