Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome and String Reversal

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

Your question is Palindrome and String Reversal. 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

Given a string s, determine whether it is a palindrome and also return the reverse of the string. A palindrome reads the same forward and backward.

Implement a function that returns a tuple (is_palindrome, reversed_string) where is_palindrome is a boolean and reversed_string is the characters of s in reverse order.

Formal Specification

  • Input: A string s
  • Output: A tuple (bool, str)
    • The first value is True if s is a palindrome, otherwise False
    • The second value is the reversed string
  • Comparison is case-sensitive and includes all characters.

Constraints

  • 0 <= len(s) <= 10^5
  • s may contain letters, digits, spaces, and punctuation
  • Comparison is case-sensitive and exact
  • The function should handle the empty string

Function Signature

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