We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f2dc01f + 17c8f83 commit e502471Copy full SHA for e502471
2370. Longest Ideal Subsequence
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+
4
+ int solve(string&s, int k){
5
6
+ vector<int>tab(26);
7
8
+ int i, j, maxi = 0;
9
10
+ for(i = s.length()-1; i>-1; i--){
11
+ for(j = 0; j<=25; j++){
12
+ if(abs(s[i]-(j+97))<=k && tab[j]){
13
+ tab[s[i]-97] = max(tab[s[i]-97], tab[j]);
14
+ }
15
16
+ tab[s[i]-97]++;
17
+ maxi = max(maxi, tab[s[i]-97]);
18
19
+ return maxi;
20
21
22
+ int longestIdealString(string s, int k) {
23
+ return solve(s, k);
24
25
+};
0 commit comments