Tap here to switch tabs
Problem
Submissions

Problem: Longest Ideal Subsequence

med
30 min
Try to solve the Longest Ideal Subsequence problem.

Statement

You are given a string s consisting of lowercase English letters and an integer k.

A string t is defined as an ideal string if it satisfies the following conditions:

  • t is a subsequence of s.

  • The absolute difference in the alphabetical positions of every two adjacent characters in t is less than or equal to k.

Return the length of the longest ideal string.

Note: A subsequence is a string derived from another string by deleting some or no characters without changing the relative order of the remaining characters.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 0≤0 \leq k ≤25\leq 25

  • s consists of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Ideal Subsequence

med
30 min
Try to solve the Longest Ideal Subsequence problem.

Statement

You are given a string s consisting of lowercase English letters and an integer k.

A string t is defined as an ideal string if it satisfies the following conditions:

  • t is a subsequence of s.

  • The absolute difference in the alphabetical positions of every two adjacent characters in t is less than or equal to k.

Return the length of the longest ideal string.

Note: A subsequence is a string derived from another string by deleting some or no characters without changing the relative order of the remaining characters.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 0≤0 \leq k ≤25\leq 25

  • s consists of lowercase English letters.