Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Reverse String Without Libraries
00:00
5 left

Reverse String Without Libraries

MediumPython

Problem

How would you reverse a string without using libraries, and also change the first letter to uppercase and the last letter to lowercase?

Implement reverse_and_change_case(s) without using string slicing, reversed(), .upper(), or .lower(). Return the transformed string. Inputs contain ASCII letters only. For an empty string, return an empty string. For a one-character string, uppercase that character.

Input and Output

s is a string, and the function returns a string.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains ASCII letters only
  • Do not use string slicing, reversed(), upper(), or lower()

Function Signature

def reverse_and_change_case(s):
Interviewer

Your question is Reverse String Without Libraries. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.