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....
-
A $3000 loan at 11% was made on March 1. Two payments of $1000 each were made on May 1 and June 1. What payment on July 1 will pay off the loan?
-
A 2.5-cm-OD, 2-cm-ID copper pipe carriers liquid oxygen to the storage site of a space shuttle at ??183?C and 0.04 m3/min. The ambient air is at 21?C and has a dew point of 10?C. How much insulation...
-
Apply the marketing-myopia concept to print media, magazines, and newspapers. What is the implication?
-
Exeter Corporation has recently begun a continuous improvement campaign. As a consequence, there have been many changes in operating procedures. Progress has been slow, particularly in trying to...
-
A young child pushes her stuffed plush cow down a frictionless slide at the playground. The slide has a height h. The cow exits the slide horizontally at the bottom. The cow slides along the level...
-
Assume today is t=0. A 10-year fixed rate bond with a 5% coupon rate is selling at par (annual coupons). From $200 FV of this bond, we form a floater and an inverse floater by equally splitting its...
-
Google Lens is a useful tool used for identifying images. Our objective is to be able to correctly identify flowering plants. In a sample of 140 plants, the following results are obtained. Use this...
-
Battery written on it (9mAh). How much time is required for this battery by providing us with a constant current of intensity (0.4mA)?
-
A tiny particle with mass 5gr and charge -1mC enters in a rectangular uniform magnetic field region with a speed of 6cm/s and leaves with the same speed as shown in the figure. The region has...
-
Acceleration due to gravity on the planet Mars is 38% as strong as the pull of gravity on Earth's surface. 1) What is the numerical value of the acceleration on Mars? (3 Marks) 2) If an astronaut on...
-
The speed of electron is measured to with in an uncertainty of 2 104| ms in one dimension. What is the minimum width required by the electron to be confined in an atom?
-
Forces F and fs act on a block as shown in the figure below and the block slides to the right in the horizontal plane. Force F makes an angle of 0 = 60 with the horizontal and its magnitude is 10 N....
-
Blooper's analysts have come up with the following revised estimates for its magnoosium mine: Conduct a sensitivity analysis for each variable and range and compute the NPV for each. Use spreadsheet...
-
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...
-
Parents with a child in subsidized childcare in the province of Qubec, Canada, pay a basic amount and, depending on family income, may pay an additional amount. As of January 1, 2017, families with a...
-
A firm in the state of Karnataka in India can source one of its factors of production either within the state, \(F_{K}\), or from the neighboring state of Maharashtra, \(F_{M}\). Assume the quality...
-
A firm has the cost curve \(C(q)=25+q^{2}\). Show how the firm's average cost varies with output. Is there a minimum average cost and, if so, at what level of output is average cost minimized?
Study smarter with the SolutionInn App