Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Even-Length String Logic
00:00
5 left

Even-Length String Logic

EasyPython

Problem

Insurity policy workflows may need a deterministic string transformation before displaying or processing values in ClaimsXPress. Implement a function that examines the length of an input string and returns the original string when its length is even, or the characters in reverse order when its length is odd.

The transformation must preserve every character, including spaces, punctuation, digits, and letter case. The parity decision must use Python's standard string length, so each Unicode code point contributes one to the length.

Formal Specification

  • Input: s, a non-null Python str.
  • Output: A Python str containing either the original value or its reversal.
  • If len(s) % 2 == 0, return s unchanged.
  • Otherwise, return s reversed.
  • Do not modify the input string. Python strings are immutable, so returning a new reversed string is acceptable.

Constraints

  • 0 <= len(s) <= 10^5
  • s is a non-null Python string
  • s may contain Unicode characters, whitespace, punctuation, and digits
  • The input string must not be modified

Function Signature

def transform_policy_string(s):
Interviewer

Your question is Even-Length String Logic. 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.