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
Reverse Words and Check Anagrams
00:00
5 left

Reverse Words and Check Anagrams

EasyPython

Problem

For a text-processing utility used in Alten Calsoft Labs tooling, implement one function that performs two independent string operations. First, reverse the order of words in a sentence. Second, determine whether two strings are anagrams.

A word is any maximal sequence of non-whitespace characters. Preserve each word's characters exactly, collapse consecutive whitespace between output words, and return an empty string for input containing only whitespace. For the anagram check, comparison is case-insensitive and ignores every character that is not an ASCII letter or digit.

Formal Specification

Implement analyze_strings(s1, s2). It receives two strings and returns a dictionary with:

  • reversed: the words of s1 in reverse order, joined by one space.
  • anagram: a Boolean indicating whether normalized s1 and s2 contain the same letters and digits with the same frequencies.

The word reversal and anagram check must be computed independently. Do not use sorting for the primary solution.

Constraints

  • 0 <= len(s1), len(s2) <= 10^5
  • Inputs contain ASCII characters
  • Anagram normalization retains only ASCII letters and digits
  • Anagram comparison is case-insensitive
  • Words are separated by arbitrary whitespace

Function Signature

def analyze_strings(s1, s2):
Interviewer

Your question is Reverse Words and Check Anagrams. 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.