Description
Solutions
Submission
Find Length of Longest Good Subsequence

A good subsequence is defined as any subsequence obtained from a string by removing 0 - any numbers of characters. The length of the subsequence should be even. If the length of the subsequence is m then the first m/2 characters should be equal and the next m/2 characters should be equal. For example, '2222', '333444' are good subsequences, while '2221', '2344234' are not good subsequences.

Find the length of the longest good subsequence.

Function Description

Complete the function findLengthOfLongestGoodSubsequence in the editor.

findLengthOfLongestGoodSubsequence has the following parameter:

  1. String s: the string to analyze

Returns

int: the length of the longest good subsequence

Example 1:

Input:  s = "2222"
Output: 4
Explanation:
The entire string is a good subsequence since the first two characters '22' are equal and the next two characters '22' are also equal. Hence, the length of the longest good subsequence is 4. (Provided by Groot with 🧡 from the west coast. PLS DONT HESITATE to correct me if you find it wrong. Many thanks in advance!)

Example 2:

Input:  s = "333444"
Output: 6
Explanation:
The entire string is a good subsequence since the first three characters '333' are equal and the next three characters '444' are also equal. Hence, the length of the longest good subsequence is 6. (Provided by Groot with 🧡 from the west coast. PLS DONT HESITATE to correct me if you find it wrong. Many thanks in advance!)

Example 3:

Input:  s = "2221"
Output: 0
Explanation:
There is no subsequence that meets the criteria for a good subsequence. Hence, the length of the longest good subsequence is 0. (Provided by Groot with 🧡 from the west coast. PLS DONT HESITATE to correct me if you find it wrong. Many thanks in advance!)

Example 4:

Input:  s = "2344234"
Output: 4
Explanation:
The subsequence '3443' is a good subsequence since the first two characters '34' are equal to the next two characters '34'. Hence, the length of the longest good subsequence is 4. (Provided by Groot with 🧡 from the west coast. PLS DONT HESITATE to correct me if you find it wrong. Many thanks in advance!)
Constraints:
    An unkown mystery for now
Thumbnail 0
Testcase

Result
Case 1

input:

output: