Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse String in Two Ways

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

Your question is Reverse String in Two Ways. 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

Netskope security policies may display labels in either their original or reversed form. Implement two Python functions that return the reverse of a string using different techniques.

  1. reverse_string(s) must reverse the string by iterating through its characters and building the result.
  2. reverse_string_slice(s) must reverse the string using Python slicing.

Both functions must return the same result. Do not modify the input, and treat spaces, punctuation, digits, and Unicode characters as ordinary characters.

Formal Specification

  • Input: s, a Python str containing zero or more characters.
  • Output: A new Python str containing the characters of s in reverse order.
  • Required functions: reverse_string(s) and reverse_string_slice(s).

Constraints

  • 0 <= len(s) <= 10^5
  • s is a Python string
  • s may contain ASCII or Unicode characters
  • The input string must not be modified

Function Signature

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