[IBM] 25intern OA

A list of ranges contains the start and end values of continuous ranges of integers. For example, [1, 4] denotes all integers in the range 1 to 4, or [1, 2, 3, 4]. Divide the ranges into 2 groups such that any 2 ranges that have at least one common integer belong to the same group.

Given the list of ranges, find the number of ways to distribute these ranges into 2 groups that satisfy the constraint and each group has at least one range. Since the answer can be large, compute it modulo (10^9 + 7).

Example:
Consider ranges = [[1, 5], [3, 8], [10, 15], [13, 14], [20, 100]].

  • [1, 5] and [3, 8] must belong to the same group since they have common integers 3, 4, and 5.
  • [10, 15] and [13, 14] must belong to the same group since they have common integers 13 and 14.
  • All other ranges can be distributed independently since they do not overlap.

Students in a class are asked to stand in ascending order according to their heights for the annual class photograph. Determine the number of students not currently standing in their correct positions.

Example:
height = [1, 1, 3, 3, 4, 1]

The 3 students indicated in red at indices 2, 4, and 5 are not in the right positions. The correct positions are [1, 1, 1, 3, 3, 4]. Return 3.

Function Description:
Complete the function countStudents in the editor below.

countStudents has the following parameter(s):

  • int height[n]: an array of heights in the order the students are standing

Returns:

  • int: the number of students not standing in the correct positions.

Constraints:

  • 1 ≤ n ≤ 10^5
  • 1 ≤ height[i] ≤ 10^9

我们长期稳定承接各大科技公司如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 *