Maximum length subsequence
Practice
4.3 (3 votes)
Implementation
Sorting
Algorithms
2d dynamic programming
Problem
77% Success 1168 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array A consisting of N integers. A subsequence of the array is called good if every pair of elements in the subsequence have an absolute difference of at most 10.

Task

Determine the maximum possible length of good subsequence.

Example

Assumptions

  • N = 8
  • A = [1, 9, 14, 2, 17, 14, 5, 18]

Approach

  • Subsequence: [9,14,17,14,18] is good which is the maximum length subsequence.
  • Hence the output is 5.

Function description

Complete the function solve() which takes the following 2 parameters and returns an integer as the required answer:

  • N: Represents an integer denoting the size of the array
  • A: Represents an array of N integers

Input format

Note: This is the input format you must use to provide custom input (available above the Compile and Test button). 

  • The first line contains an integer N.
  • The second line contains an array A of N integers.

Output format

Print the maximum possible length of good subsequence.

Constraints

\(1 \leq N \leq 10^5 \\ 1 \leq A_i \leq 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
194 votes
Tags:
AlgorithmsApprovedEasyOpenReady
Points:20
6 votes
Tags:
ApprovedData StructuresEasyImplementationMerge sortSimulationSortingapproved
Points:20
87 votes
Tags:
Easy