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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Caesar Cipher Encoding Function
00:00
5 left

Caesar Cipher Encoding Function

EasyPython

Problem

Next Insurance uses lightweight text transformations in internal policy-processing tools. Implement a Caesar cipher encoder that shifts every English alphabetic character by a specified amount while preserving the original letter case.

Formal Specification

Implement encrypt_message(text, shift):

  • text is a string containing ASCII letters, digits, spaces, punctuation, and possibly other characters.
  • shift is an integer and may be positive, zero, or negative.
  • Shift uppercase letters within A-Z and lowercase letters within a-z, wrapping around at the end of each alphabet.
  • Leave digits, whitespace, punctuation, and all non-ASCII-letter characters unchanged.
  • Return the encoded string.

The shift may be larger than 26, so reduce it modulo 26. The input string must not be modified in place.

Constraints

  • 0 <= len(text) <= 10^5
  • -10^9 <= shift <= 10^9
  • Letters in the input are restricted to ASCII A-Z and a-z
  • Digits, whitespace, punctuation, and other characters must be preserved

Function Signature

def encrypt_message(text, shift):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.