Remove all vowels from a string

Quick Overview

Write a function that returns a copy of a string with every vowel removed, in either case, while all other characters keep their original order. It tests string iteration, building a new string efficiently in Python, and edge cases such as an empty input or a string made only of vowels.

Remove all vowels from a string

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Write a Python function that takes a string `s` and returns a new string with all vowels (both lowercase and uppercase) removed. The vowels are `a`, `e`, `i`, `o`, `u` and their uppercase counterparts. The function should handle any input string and keep the non-vowel characters in their original order. ### Function Signature ```python def remove_vowels(s: str) -> str: ... ``` ### Rules - The ten vowel characters are `a`, `e`, `i`, `o`, `u`, `A`, `E`, `I`, `O`, `U`. The letter `y` is not a vowel. - Every other character, including spaces, digits and punctuation, stays in the output in its original relative order. - If `s` is empty or contains only vowels, return the empty string. ### Constraints - `0 <= len(s) <= 10^4` ### Examples ```text Input: s = "hello" Output: "hll" ``` Removing `e` and `o` leaves `h`, `l`, `l` in their original order. ```text Input: s = "AEIOUaeiou" Output: "" ``` Every character is a vowel, so nothing is left. ```text Input: s = "Python 3.12!" Output: "Pythn 3.12!" ``` Only the `o` is removed. The `y`, the space, the digits and the punctuation all stay where they were.

Overview: Write a function that returns a copy of a string with every vowel removed, in either case, while all other characters keep their original order. It tests string iteration, building a new string efficiently in Python, and edge cases such as an empty input or a string made only of vowels.

Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Write a Python function that takes a string s and returns a new string with all vowels (both lowercase and uppercase) removed. The vowels are a, e, i, o, u and their uppercase counterparts. The function should handle any input string and keep the non-vowel characters in their original order.

Function Signature

def remove_vowels(s: str) -> str:
    ...

Rules

  • The ten vowel characters are a , e , i , o , u , A , E , I , O , U . The letter y is not a vowel.
  • Every other character, including spaces, digits and punctuation, stays in the output in its original relative order.
  • If s is empty or contains only vowels, return the empty string.

Constraints

  • 0 <= len(s) <= 10^4

Examples

Input: s = "hello"
Output: "hll"

Removing e and o leaves h, l, l in their original order.

Input: s = "AEIOUaeiou"
Output: ""

Every character is a vowel, so nothing is left.

Input: s = "Python 3.12!"
Output: "Pythn 3.12!"

Only the o is removed. The y, the space, the digits and the punctuation all stay where they were.