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
icon
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) {
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Counting Sort
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education