Given an array of bad numbers and a range integers, determine the longest segment of integers...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
The following JAVA code determines the longest segment of integers within that inclusive range that ... View the full answer
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
The Quiznos franchise agreement does not include any prohibitions against encroachment, so the franchisor believes it has the right to open new locations where it chooses. Don Boroian, a franchise...
-
Given an array of n elements, give a linear-time algorithm to rotate the string k positions. That is, if the array contains a0, a1, , an1 , the rotated array is ak, ak+1, , an-1, a0, , ak1. Use at...
-
Given an array of integers of any size, n 4, write an algorithm as a pseudo code (not a program!) that would reverse every two consecutive elements of the left half of the array (i.e. reverse...
-
A teacher traces a small circle on the palm of a kindergartener's hand to let him know it is time for free play. What type of disability does this child most likely have? A. Traumatic Brain Injury B....
-
Which error, Type I or Type II, would usually be considered more serious for decisions in the following tests? Explain why. a. A trial to test a murder defendants claimed innocence, when conviction...
-
Determine the loop gain \(T\) for the circuit in Figure P12.49. The transistor parameters are: \(h_{F E}=100, V_{B E}(\mathrm{on})=0.7 \mathrm{~V}\), and \(V_{A}=\infty\). is Rif V+=+10 V ww RCI = 40...
-
Pluto Corporation issued \(\$ 400,000\) of \(7 \%, 20\) year bonds payable on March 31, 2006. The bonds were issued at 100 and pay interest on March 31 and September 30. Record (a) issuance of the...
-
Assume today's settlement price on a CME EUR futures contract is $1.3140/EUR. You have a short position in one contract. Your performance bond account currently has a balance of $1,700. The next...
-
What drives competition in commercial aircraft business? Is competition fair in commercial aircraft? As Boeing, what are your options for responding to Airbus? What would you do in 1991?
-
1. What issues should be of concern to Margaret in deciding whether Dairy and Cheese should accept the reaudit engagement? 2. What are Marks ethical obligations in this matter? Should he discuss the...
-
Choose a person with whom you see an issue differently : Parent/Child, Friend/Friend Teacher/Student, Boyfriend/Girlfriend, spouse/spouse Boss/Employee, Brother/Sister First, explain the Pillow...
-
What steps should be followed by a business considering outsourcing data processing to an American company?
-
How does Canada protect an individuals privacy in ecommerce transactions?
-
Have you ever seen a speaker make an error when analyzing the audience or context? How did it affect the presentation?
-
What protection is available for employee personal information?
-
List two examples of information and communications technologies (IC Ts).
-
c Fig.(1) shows the head on collision between two masses. The coeffi cient of restitution is e, where 1 > e > 0. Derive an expression for V At rest Before collision m2 After collision m2 Figure 1:...
-
Which should drive action planning more, strengths or weaknesses? That is, is it more important to build on your strengths or to reduce your weaknesses? Explain.
-
What are the benefits of knowing how to motivate employees? Describe several important motivational theories and strategies that apply them.
-
What regulations apply to non-European Union persons purchasing a business in a European Union country like France? What are the visa, residency, and work permit requirements for a non-European Union...
-
Describe Threadless.coms unique business model. Why do you think it has been so successful and also profitable? Suggest other types of products that could use this model and some which could not use...
-
Following are several tests of controls introduced in the chapter: Examine periodic reports by non-Purchasing Department personnel regarding purchase prices and practices. Observe Receiving...
-
Harold Brodkey plans to apply sequential sampling to the receiving controls used by the Ozyck Corporation, a December 31, 1999 year end manufacturer and supplier of home lighting fixtures. Based on a...
-
Few departments within a corporation, not-for-profit institution, or governmental entity can have quite as significant an influence on cost containment as Purchasing, since the purchasing function...
Study smarter with the SolutionInn App