Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Picking Tickets Consider an array of n ticket prices, tickets. A number, m, is defined as the size of some subsequence, s, of tickets

image text in transcribedimage text in transcribed
1. Picking Tickets Consider an array of n ticket prices, tickets. A number, m, is defined as 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 absolute difference between any elements j and j + 1 would be either O or 1. Determine the maximum length of a subsequence chosen from the tickets array. Example tickets = [8, 5, 4, 8, 4] Valid subsequences, sorted, are {4, 4, 5} and 18, 8}. These subsequences have m values of 3 and 2, respectively. Return 3. Function Description Complete the function maxTickets in the editor below. maxTickets has the following parameter(s): int tickets[n]: an array of integers Returns int: an integer that denotes the maximum possible value of mReturns int: an integer that denotes the maximum possible value of m Constraints . 1sns 105 . 1 s tickets[i] s 109 Input Format For Custom Testing The first line contains an integer, n, that denotes the number of elements in tickets. Each line i of the n subsequent lines (where 0 s i <>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

The value of the field PizzaStore.INSERTSQL is not used line 32

Answered: 1 week ago