Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

String Capitalization Without Built-ins

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is String Capitalization Without Built-ins. Start with the requirements on the right.

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.

Problem

Barracuda Networks security tooling may need to normalize or toggle text without relying on convenience APIs. Implement a function that changes the capitalization of ASCII letters in a string without using native Python functions or string methods such as upper(), lower(), swapcase(), ord(), chr(), len(), range(), or str.translate().

The mode argument is one of "upper", "lower", or "toggle". Convert only the 52 English alphabetic characters. Preserve digits, whitespace, punctuation, symbols, and all character ordering. The input is guaranteed to contain only ASCII characters.

Formal Specification

  • Input: text, a string of ASCII characters, and mode, one of the three permitted mode strings.
  • Output: A new string with the requested capitalization transformation.
  • Do not modify the input string. Do not use native functions or string case-conversion methods.

Constraints

  • 0 <= text length <= 10^5
  • text contains ASCII characters only
  • mode is "upper", "lower", or "toggle"
  • Only ASCII alphabetic characters may be changed
  • Native Python functions and string methods for case conversion are prohibited

Function Signature

def transform_case(text, mode):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output