Company: Walmart

Difficulty: medium

Problem Statement

Longest Good Subsequence A subsequence is obtained from a string by removing zero or more characters without changing the order of the remaining characters. A subsequence is called good when its length m is positive and even, the first m / 2 characters are all equal to one another, and the last m / 2 characters are all equal to one another. The character used in the two halves may be the same or different. For example, "2222" and "333444" are good, while "222" and "234234" are not good themselves. You are given a string s of digits. Return the length of the longest good subsequence of s , or 0 when no positive even length good subsequence exists. Input Format A single line containing the string s , made up of the digits 0 - 9 . Output Format Print a single integer: the length of the longest good subsequence of s . Constraints 1 <= s.length <= 100000 Each character of s is a digit from '0' to '9' . Examples ### Example 1 Input: 2222 Output: 4 The entire string is good. Its first h

More Walmart OA questionsInterview experiences