Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write C++ code 2 Cover intervals You are given a sorted unique integer array A. An interval [a, b] is the set of all integers

write C++ code

2 Cover intervals You are given a sorted unique integer array A. An interval [a, b] is the set of all integers from a to b (inclusive). You are to write a function called ECSmallestCoverIntervals that returns the smallest number of intervals of A that cover all the numbers in the array exactly. That is, each element of A is covered by exactly one of the intervals, and there is no integer x such that x is in one of the intervals but not in A. For example, suppose A = [0, 1, 2, 4, 5, 7], then the function returns 3: there are three cover intervals: [0, 2], [4, 5], [7, 7]. As another example, for B = [0, 2, 3, 4, 6, 8, 9], the function returns 4.

starter code

// Given a sorted list, find the smallest number of covering intervals

// For example, if A={1,2,3,5,6,9}, there are three covering intervals [1,3], [5,6] and [9]

int ECSmallestCoverIntervals(const int arrInts[], int szArr)

{

// arrInts: sorted array of integers; szArr: number of integers in the array

// Your code here

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions