6. Picking Tickets Consider an array of n ticket prices, tickets. A number, m, is defined as the size of some subsequence of tickets, s, where each element covers an unbroken range of integers. That is, if the elements in s are sorted, the absolute difference between any elements / and j+ 1 is either 0 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 {8, 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]: the ticket prices Returns int: the maximum possible value of m Constraints 1sns105 • 1 ≤ tickets[i] ≤ 10⁹ • 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } 29 30> public class Solution {" class Result { * Complete the 'maxTickets' function below. } * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY tickets as parameter. */ public static int maxTickets (List tickets) {
6. Picking Tickets Consider an array of n ticket prices, tickets. A number, m, is defined as the size of some subsequence of tickets, s, where each element covers an unbroken range of integers. That is, if the elements in s are sorted, the absolute difference between any elements / and j+ 1 is either 0 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 {8, 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]: the ticket prices Returns int: the maximum possible value of m Constraints 1sns105 • 1 ≤ tickets[i] ≤ 10⁹ • 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } 29 30> public class Solution {" class Result { * Complete the 'maxTickets' function below. } * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY tickets as parameter. */ public static int maxTickets (List tickets) {
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![6. Picking Tickets
Consider an array of n ticket prices, tickets. A number, m, is
defined as the size of some subsequence of tickets, s, where
each element covers an unbroken range of integers. That is, if
the elements in s are sorted, the absolute difference between
any elements jand j + 1 is either 0 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 {8, 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]: the ticket prices
Returns
int: the maximum possible value of m
Constraints
• 1≤n≤105
• 1 ≤ tickets[i] ≤ 10⁹
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30> public class Solution {...
class Result {
}
* Complete the 'maxTickets' function below.
★
}
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY tickets as parameter.
*/
public static int maxTickets(List<Integer> tickets) {](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6cf78908-a1f9-4330-9ece-f4021df10613%2Fa997f97a-94d0-4b8c-a0e1-6fa2ef2961dc%2Ff145xo_processed.png&w=3840&q=75)
Transcribed Image Text:6. Picking Tickets
Consider an array of n ticket prices, tickets. A number, m, is
defined as the size of some subsequence of tickets, s, where
each element covers an unbroken range of integers. That is, if
the elements in s are sorted, the absolute difference between
any elements jand j + 1 is either 0 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 {8, 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]: the ticket prices
Returns
int: the maximum possible value of m
Constraints
• 1≤n≤105
• 1 ≤ tickets[i] ≤ 10⁹
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30> public class Solution {...
class Result {
}
* Complete the 'maxTickets' function below.
★
}
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY tickets as parameter.
*/
public static int maxTickets(List<Integer> tickets) {
![Input Format For Custom Testing
The first line contains an integer, n, the number of elements
in tickets.
Each line i of the n subsequent lines (where 0≤i<n)
contains an integer, tickets[i].
Sample Case 0
Sample Input 0
STDIN
4
W NA P
4
13
2
3
Function
3
tickets [] size n = 4
tickets =
Sample Output 0
Explanation 0
[4, 13, 2, 3]
There are two subsequences of tickets that contain
consecutive integers when sorted: {2, 3, 4} and {13}. These
subsequences have m values of 3 and 1, respectively.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6cf78908-a1f9-4330-9ece-f4021df10613%2Fa997f97a-94d0-4b8c-a0e1-6fa2ef2961dc%2F2593cyk_processed.png&w=3840&q=75)
Transcribed Image Text:Input Format For Custom Testing
The first line contains an integer, n, the number of elements
in tickets.
Each line i of the n subsequent lines (where 0≤i<n)
contains an integer, tickets[i].
Sample Case 0
Sample Input 0
STDIN
4
W NA P
4
13
2
3
Function
3
tickets [] size n = 4
tickets =
Sample Output 0
Explanation 0
[4, 13, 2, 3]
There are two subsequences of tickets that contain
consecutive integers when sorted: {2, 3, 4} and {13}. These
subsequences have m values of 3 and 1, respectively.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education