Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Picking Tickets Consider an array of n ticket prices, tickets. We define a number, m, to be the size of some subsequence, s, of

 image
   
image
image
image

Picking Tickets Consider an array of n ticket prices, tickets. We define a number, m, to be the size of some subsequence, s, of tickets where each element covers an unbroken range of integers; that is to say, if you were to sort the elements in s, the difference between any elements j andj + 1 would be either 0 or 1. For example, tickets = [8, 5, 4, 8, 4] gives us sorted subsequences][4, 4, 5) and (8, 8); these subsequences have m values of 3 and 2, respectively. Complete the maxTickets function in the editor below. It has one parameter: an array of integers, tickets. The function must return an integer denoting the maximum possible value of m. Input Format Locked stub code in the editor reads the following input from stdin and passes it to the function: The first line contains an integer, n, denoting the number of elements in tickets. Each line of the n subsequent lines (where 0 si Constraints 0n2 x 106 0 tickets, 2 x 106 Output Format Print the maximum value of m (i.e., the size of the largest unbroken sequence of sorted consecutive integers whose adjacent elements have a maximum absolute difference of 1). Sample Input 0 4 13 2 3 Sample Output 0 3 Explanation 0 tickets=14, 13, 2, 31 There are two subsequences of tickets that contain consecutively Ask me anything 0 a rint the maximum value of m (i.e., the size of the largest unt equence of sorted consecutive integers whose adjacent elem a maximum absolute difference of 1). Sample Input 0 4 4 13 23 Sample Output 0 3 Explanation 0 tickets = [4, 13, 2, 3] There are two subsequences of tickets that contain consecutively numbered integers: (2, 3, 4) and (13). These subsequences have m values of 3 and 1, respectively. We return the maximum value of m. which is 3. Ask me anything 0 1> #include 1234 56 using namespace std; 6 /* 7 8 9 10 11 12 Complete the function below. int maxTickets (vector tickets) { tickets) }

Step by Step Solution

3.41 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

The required c function implementation is as follows Function to find the maximum size of a subseque... 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_2

Step: 3

blur-text-image_3

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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students explore these related Programming questions

Question

Prove that 2 i=1 + N

Answered: 3 weeks ago

Question

31. How does Antabuse workpg78

Answered: 3 weeks ago