
TSMC's main interview process is divided into:
- Qualification Audit
- HackerRank Test
- Supervisor Interview
- Factory Fitness, English Test
- HR Interview
The next step is to share the real questions of the Hackerrank OA program quiz.
1. Group Division
A university has admitted a group of n
Students with varying skill levels. To better accommodate the students, the university has decided to create classes tailored to these skill levels. placement examination returns a skill level for each student, represented by an array levels[]
, where levels[i]
denotes the skill level of student i
.
All students within a group must have skill levels that are within a specified range. maxSpread
The goal is to determine the minimum number of groups that must be formed to ensure that no group contains students whose skill levels differ by more than one. differ by more than maxSpread
.
Example
Input.
n = 5
(number of students)levels = [1, 4, 7, 3, 4]
(skill levels of the students)maxSpread = 2
(the maximum allowed skill level difference within a group)
Output.
3
(minimum number of groups)
In this example, one optimal grouping is.
- Group 1: (1, 3)
- Group 2: (4, 4)
- Group 3: (7)
An alternative valid grouping could be.
- Group 1: (1)
- Group 2: (3, 4, 4)
- Group 3: (7)
In both cases, we form 3 groups, and this is the minimum number of groups that can be formed. There's no way to form fewer than 3 groups given the maxSpread
condition.
Ideas for solving the problem
- Sorting Skill Levels: Start by sorting students' skill levels from smallest to largest. This ensures that when traversing students, we only need to focus on skill differences between neighboring students.
- Greedy strategy grouping: traverse the sorted list of students and try to place each student into the current group until the maximum skill difference in the current group exceeds maxSpread. If it exceeds, start a new group.
2. Linked List Creation
There is a singly linked list of n
nodes. Each node is an instance of a SinglyLinkedListNode
, which has an integer value data
and a pointer to the next node, and a pointer to the next node, and a pointer to the next node. next
. Perform the following operations to generate a new linked list: .
- Select all the nodes at odd positions.
- Append these nodes to the new linked list, keeping them in their original order.
- Delete these nodes from the old linked list.
- Repeat from step 1 until there are no nodes left in the old linked list.
Return a reference to the head of the final linked list.
Note: Extra memory, other than creating some new nodes, should not be used for the implementation.
Ideas for solving the problem
- Define the linked table node structure: each linked table node contains data (the node value) and next (a pointer to the next node).
- Select Odd Position Nodes: We can get the nodes in odd position by traversing the chain table. Nodes at odd positions are nodes at positions 1, 3, 5, etc.
- Modify the pointer connection:
- Gets the nodes in odd positions from the original chain table and adds them one by one to the end of the new chain table.
- When deleting these nodes, it is important to make sure that the predecessor node of the original linked table is correctly pointed to the next node to avoid breaking the chain.
- Repeat operation: After each node in odd position is processed, you need to skip one node (i.e. delete the next node of the currently processed node) and continue this operation until the chain table is empty.
3. String compression and decompression
Various compression methods are employed to minimize the size of messages transmitted over the internet. A specific algorithm compresses a given string by indicating the total number of consecutive occurrences of each character. A specific algorithm compresses a given string by indicating the total number of consecutive occurrences of each character. "aabbaa"
can be compressed as "a2b2a2"
. The characters of each character are grouped as follows.
a
occurs two times consecutively.b
occurs two times consecutively.a
occurs two times consecutively.
If a character occurs only once, it is added to the compressed string. If it occurs consecutively, the character is added to the string followed by an integer representing the number of consecutive occurrences. If it occurs consecutively, the character is added to the string followed by an integer representing the number of consecutive occurrences. "a2b2a2"
.
Function Description.
Complete the function compressedString
in the editor below. The function must return the compressed form of the message.
compressedString has the following parameter(s). message
: a string.
Returns: string
: the compressed message.
def compressedString(s).
# Write your code here
n = len(s)
ans = ""
ans = "
while i < n.
j = i + 1
while j 1.
ans += str(j - i)
i = j
return ans
The idea is to iterate through the string, counting the number of consecutive occurrences of each character and combining the characters with the number of occurrences to produce a compressed string.
Learn More
Tsmc one acre and three quarters
TSMC Recruitment
TSMC Interview Lazy Person's Kit: Interview Process, Interview Questions TSMC IT Careers
If you also need our TSMC hackerrank cheating service and interview assistance, substitute interview services, please Contact Us Now.