Longest special subsequences
Practice
2.7 (13 votes)
Algorithms
Dynamic programming
Java
Medium
Optimization
Python
Two dimensional
Problem
53% Success 1872 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a string S of the length n consisting of only lowercase English alphabets.
If the two consecutive characters in a subsequence have a difference that is no more than k, then it is called a special subsequence. Find the length of the longest special subsequence.
Input format
- First line: t (number of test cases)
- Next t line: Three space-separated integers n, k, and S
Output format
For each test case, print the length of the longest special subsequence in a new line.
Constraints
\(1 \le t \le 10\)
\(1 \le n \le 10^{5}\)
\(1 \le k \le 26\)
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpen
Points:30
Tags:
RecursionDynamic ProgrammingAlgorithmsRecursive dp2D dynamic programming
Points:30
7 votes
Tags:
Dynamic ProgrammingMediumTwo dimensional
Editorial
Login to unlock the editorial