學長最近完成了一份到 臺積電OA (TSMC)的線上測驗(OA)真題,發出來分享一下~如果你正在準備臺積電(TSMC)的 Online Assessment,首先要有心理準備:題目涵蓋範圍廣,從基礎程式設計、資料處理到邏輯推理都有可能出現。相比其他科技公司,臺積電更注重候選人的工程思維和實際問題解決能力,所以光靠刷題不夠,需要理解題目的本質和高效解法。我自己在做 OA 時發現,合理規劃時間、抓住每道題的關鍵點非常重要,否則很容易在細節上浪費太多精力。
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.
Example
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. As a result, the answer is [0, 1, 2, 4, 6].
Python Code
def findDistinctGoodnessValues(arr):
n = len(arr)
# goodness_values: A collection that stores all the different goodness values.
Goodness_values = set()
dp = [set() for _ in range(n)]
# For each element arr[i], repeatedly operate all previous elements arr[j], where arr[j]<arr[i]
# For each goodness value in dp[j], calculate a new goodness value by performing a bitwise OR with arr[i] and add it to new_values
# Add arr[i] itself to new_values to account for 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 collection
for val in new_values:
goodness_values.add(val)
# Add 0 to the set to include the goodness 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 third of an acre of land
- TSMC Company Introduction
- TSMC interview guide: interview process, interview questions
聯絡我們
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.