Question: Given an array of bad numbers and a range integers, determine the longest segment of integers within the range that does not include any

Given an array of bad numbers and a range integers, determine the                      include any bad numbers. Constraints • 1sns 105 • 1 s badNumbers[i]s 109 • badNumbers contains distinct elements. • 1 s lower

                                                        

Given an array of bad numbers and a range integers, determine the longest segment of integers within the range that does not include any bad of numbers. Example n = 6 badNumbers [37, 7, 22, 15, 49, 60] lower = 3 upper - 48 The segments in the range 3 to 48, inclusive, without any bad numbers are: [3, 6), [8, 14), [16, 21), [23, 36) and [38, 48). The longest segment is [23, 36] and it is 14 elements long, thus the return value is 14 Function Description Complete the function goodSegment in the editor below. goodSegment has the following parameter(s): int badNumbers{n]: an array of integers int lower: an iteger, the lower bound, inclusive int upper an integer, the upper bound, inclusive Returns: int. an integer denoting the length of longest contiguous sequence of natural numbers in the range lower to upper, inclusive, which does not include any bad numbers. Constraints include any bad numbers. Constraints 1sns 105 1 s badNumbers[ijs 10 badNumbers contains distinct elements. 1 s lower s upper s 10 v Input Format For Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains an integer, n, the number of elements in badNumbers. Each of the next n lines contains an integer, badNumbers[i). The next line contains an integer, lower, the lower range limit, inclusive. The last line contains an integer, upper, the upper range limit, inclusive. Sample Case 0 Sample Input 0 STDIN Function badNumbers [] size n = 4 badNumbers [5, 4, 2, 15 4. 15 1. Lower = 1 10 upper= 10

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The following JAVA code determines the longest segment of integers within that inclusive range that ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!