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....
-
Continuing the previous problem, perform a sensitivity analysis on the selling price of VXPs. Let this price vary from $500 to $650 in increments of $10, and keep track of the values in the changing...
-
Using the accrual accounting basis, when are revenues and expenses recognized?
-
Personality dynamics is represented by ____________. (a) self-esteem and selfefficacy (b) Type A/Type B orientation (c) self-monitoring (d) Machiavellianism
-
Give personal examples of (a) Approachapproach conflict, (b) Avoidanceavoidance conflict, and (c) Approach avoidance conflict.
-
Linear Regression - Christmas Trees The following table gives the total number of live Christmas trees sold, in millions, in the United States from 2004 to 2011. (Source: Statista.com). t number of...
-
As the auditor of Clearwater County you learn that various assets are subject to spending constraints. Indicate how each of the following constraints would affect the countys reported fund balance...
-
Premier Products, Inc. manufactures tennis rackets. Premier Products has grown extensively over the past two years. While the company has been very profitable, President Mark Harrison is concerned...
-
Reverse osmosis process is used for drinking water production using seawater and brackish water.A small seawater reverse osmosis (SWRO) plant with 200 m membrane area is presented in the following...
-
A company makes standard 115-inch-wide rolls of thin sheet metal and slits them into smaller rolls to meet customer orders for widths of 13, 16, and 25 inches. The demands for these widths vary from...
-
The pinion S (see FigQ3) has 15 teeth, and is connected to a motor shaft. The wheel P has 20 teeth and gears with S and also with a fixed annulus wheel A. The pinion C has 15 teeth and is fixed to...
-
Portions of the financial statements for Hawkeye Company are provided below. HAWKEYE COMPANY Income Statement For the Year Ended December 31, 2013 Sales Cost of goods sold Gross margin Salaries...
-
A nonredundant system with 100 components has a design-life reliability of 0.90. The system is redesigned so that it has only 70 components. Estimate the design life of the redesigned systems,...
-
Birch Manufacturers has provided the following information regarding the two products that it sells: Sales price per unit Variable cost per unit Jet Boats Ski Boats $10,000 $6,000 $24,000 $18,000...
-
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...
-
Ernest Petroleum began operations January 1, 2015. Transactions for the first three years include the data below. Using that data: a. Prepare journal entries assuming full cost (ignore revenue...
-
Data as of 12/31/15 for Dry Hole Oil Companys U.S. properties are as follows: (This problem is similar to problem 14 in chapter 6.) Dry Holes activities during 2016 were as follows: a. Use T-accounts...
-
Cowboy Oil Corporation began operations in 2016. Give the entries, assuming the following transactions in the first three years of operations. Calculate DD&A twice, once assuming no exclusions and...
Study smarter with the SolutionInn App