Points That Intersect With Cars

You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the i^th car and endi is the ending point of the i^th car.

Return the number of integer points on the line that are covered with any part of a car.

Example 1
Inputnums = [[3,6],[1,5],[4,7]]
Output7
All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.
Example 2
Inputnums = [[1,3],[5,8]]
Output7
Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8, so there are a total of 7 points.

Constraints

  • 1 <= nums.length <= 100
  • nums[i].length == 2
  • 1 <= starti <= endi <= 100

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate