|
| 1 | +package com.github.streams.practice.b_medium.strings.problems; |
| 2 | + |
| 3 | +import com.github.streams.practice.b_medium.strings.StringProblemsSolution; |
| 4 | +import org.junit.jupiter.api.Assertions; |
| 5 | +import org.junit.jupiter.api.Disabled; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +/// |
| 9 | + /// You are given a string s consisting of lowercase English letters ('a' to 'z'). |
| 10 | + /// |
| 11 | + /// Your task is to: |
| 12 | + /// |
| 13 | + /// Find the vowel (one of 'a', 'e', 'i', 'o', or 'u') with the maximum frequency. |
| 14 | + /// Find the consonant (all other letters excluding vowels) with the maximum frequency. |
| 15 | + /// Return the sum of the two frequencies. |
| 16 | + /// |
| 17 | + /// Note: If multiple vowels or consonants have the same maximum frequency, you may choose any one of them. If there are no vowels or no consonants in the string, consider their frequency as 0. |
| 18 | + /// |
| 19 | + /// |
| 20 | + /// |
| 21 | + /// The frequency of a letter x is the number of times it occurs in the string. |
| 22 | + /// |
| 23 | + /// |
| 24 | + /// Example 1: |
| 25 | + /// |
| 26 | + /// Input: s = "successes" |
| 27 | + /// |
| 28 | + /// Output: 6 |
| 29 | + /// |
| 30 | + /// Explanation: |
| 31 | + /// |
| 32 | + /// The vowels are: 'u' (frequency 1), 'e' (frequency 2). The maximum frequency is 2. |
| 33 | + /// The consonants are: 's' (frequency 4), 'c' (frequency 2). The maximum frequency is 4. |
| 34 | + /// The output is 2 + 4 = 6. |
| 35 | + /// Example 2: |
| 36 | + /// |
| 37 | + /// Input: s = "aeiaeia" |
| 38 | + /// |
| 39 | + /// Output: 3 |
| 40 | + /// |
| 41 | + /// Explanation: |
| 42 | + /// |
| 43 | + /// The vowels are: 'a' (frequency 3), 'e' ( frequency 2), 'i' (frequency 2). The maximum frequency is 3. |
| 44 | + /// There are no consonants in s. Hence, maximum consonant frequency = 0. |
| 45 | + /// The output is 3 + 0 = 3. |
| 46 | + /// |
| 47 | + /// |
| 48 | + /// Constraints: |
| 49 | + /// |
| 50 | + /// 1 <= s.length <= 100 |
| 51 | + /// s consists of lowercase English letters only. |
| 52 | + /// |
| 53 | + /// |
| 54 | + /// |
| 55 | + /// |
| 56 | + /// |
| 57 | + /// |
| 58 | + /// |
| 59 | +class Q_FrequentVowelPlusConstant { |
| 60 | + |
| 61 | + @Test |
| 62 | + @Disabled |
| 63 | + void freqVowelsPlusConstant() { |
| 64 | + final var input = "successes"; |
| 65 | + final var mySolution = StringProblemsSolution.frequentVowelPlusConstant(input); |
| 66 | + final var yourSolution = -1; |
| 67 | + |
| 68 | + Assertions.assertEquals(mySolution, yourSolution); |
| 69 | + } |
| 70 | +} |
0 commit comments