IBM Software Engieer OA questions
Anonymous User
383

Q1. In a school, there are n students who want to participate in an academic decathlon. The teacher wants to select the maximum number of students possible. Each student has a certain skill level.
For the team to be uniform, it is important that when the skill levels of its members are arranged in increasing order, the difference between any two consecutive skill levels is either 0 or 1. Find the maximum team size the teacher can form.

Example
skills = [10, 12, 13, 9, 14]
Valid teams, sorted are (9, 10}, and {12, 13, 14}. These teams have team sizes 2 and 3 respectively, so the maximum team size is 3.
Function Description
Complete the function findMax TeamSize in the editor below.
findMax TeamSize has the following parameter:
int skills[n]: the skill levels of each student
Returns
int: the maximum possible size of the team
Constraints
• 1 ≤ n≤ 10^5
• 1 ≤ skills[i] ≤ 10^9


Q2. Given a number num, two adjacent digits can be swapped if their parity is the same, that is, both are odd or both are even. For example, (5, 9) have the same parity, but (6,9) do not.
Find the largest number that can be created. The swap operation can be applied any number of time:
Example
Let num = "7596801".
• Swap 5 and 9 - "7956801"
• Swap 7 and 9 →> "9756801"
• Swap 6 and 8 -> "9758601"
The largest value possible is "9758601"

Function Description
Complete the function getLargestNumber in the editor below.
getLargestNumber has the following parameter:
string num: a string of digits
Returns
string: the largest number that can be created

Comments (5)