Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Remove Vowels and Consonants
00:00
5 left

Remove Vowels and Consonants

EasyPython

Problem

Capital Group research workflows use compact text labels that may contain letters, digits, spaces, and punctuation. Implement a function that removes vowels, consonants, or both while preserving every retained character in its original order.

Formal Specification

Given an ASCII string s and two Boolean flags, return a new string:

  1. Remove an ASCII vowel when remove_vowels is True. Vowels are a, e, i, o, and u, regardless of case.
  2. Remove an ASCII consonant when remove_consonants is True.
  3. Preserve letters that are not selected for removal.
  4. Always preserve digits, whitespace, punctuation, and other non-ASCII characters.
  5. The input string must not be modified. Return a string.

You may use a single left-to-right scan. Do not use regular expressions.

Constraints

  • 0 <= len(s) <= 10^5
  • s may contain ASCII letters, digits, whitespace, punctuation, and Unicode characters
  • remove_vowels and remove_consonants are Boolean values
  • Preserve the relative order of all retained characters

Function Signature

def filter_letters(s, remove_vowels, remove_consonants):
Interviewer

Your question is Remove Vowels and Consonants. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.