↓Skip to main content
  1. LeetCode/

LeetCode 3813: Vowel-Consonant Score

·1 min· ·
LeetCode Easy String Simulation
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2026-01-18

  • Submissions: Accepted (first try)

Approach
#

The string also contains spaces and digits; only letters count (String Template 4). With v vowels and c consonants, the score is v // c when c > 0, otherwise 0.

My Solution
#

I originally checked letters with 97 <= ord(c) <= 97 + 26 (the upper bound actually lets in {, which never appears) and used floor(v / c). Here with isalpha and integer division:

class Solution:
    def vowelConsonantScore(self, s: str) -> int:
        v = sum(ch in "aeiou" for ch in s)
        c = sum(ch.isalpha() and ch not in "aeiou" for ch in s)
        return v // c if c else 0

Complexity
#

Time O(n), space O(1).

Mistakes to Avoid
#

  • Spaces and digits are not consonants.
  • Do not divide when there are no consonants.

Interview Explanation
#

I count only letters, vowels and consonants separately. With no consonants I return 0; otherwise the integer quotient. Time O(n).

Related

LeetCode 657: Robot Return to Origin
·1 min
LeetCode Easy String Simulation
LeetCode 657 note: returning to the origin means as many U as D and as many L as R
LeetCode 844: Backspace String Compare
·2 mins
LeetCode Easy Two-Pointers String Stack Simulation
LeetCode 844 note: simulate backspaces with a stack; for O(1) space, walk from the end and count how many characters each # skips
LeetCode 415: Add Strings
·2 mins
LeetCode Easy Math String Simulation
LeetCode 415 note: add digit by digit from the ends with two pointers, tracking the carry, and append any leftover carry after the loop
LeetCode 412: Fizz Buzz
·1 min
LeetCode Easy Math String Simulation
LeetCode 412 note: check multiples of 15 first, then 5 and 3; multiples need %, not //
LeetCode 67: Add Binary
·2 mins
LeetCode Easy Math String Bit-Manipulation Simulation
LeetCode 67 note: add from the ends of both strings digit by digit, with carry sum // 2 and digit sum % 2
LeetCode 3258: Count Substrings That Satisfy K-Constraint I
·2 mins
LeetCode Easy Sliding-Window String
LeetCode 3258 note: valid means zeros <= k or ones <= k; it is invalid only when both exceed k, and after shrinking there are right - left + 1 valid substrings ending at right