[IBM] SDE NG Jan OA

1. Question 1

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 findMaxTeamSize in the editor below.

findMaxTeamSize 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⁵
  • 1 ≤ skills[i] ≤ 10⁹

2. Question 2

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 times.


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

Constraints

  • 1 ≤ length of num ≤ 10⁵
  • num consists of digits 0-9 only.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *