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
Start free
Validate JavaScript Riddle Assertions
00:00
5 left

Validate JavaScript Riddle Assertions

MediumPython

Problem

Problem Narrative

You’re building an internal hiring platform for a fintech company that screens JavaScript candidates at scale (hundreds of thousands of submissions per day). To reduce fraud and keep grading deterministic, the platform runs “vanilla JS riddles” inside a locked-down test framework. Each riddle is a tiny assertion like expect(reverse("abc")).toBe("cba").

Your job is to implement the core assertion evaluator that determines whether each riddle passes without executing JavaScript. Instead, you’ll parse and evaluate a limited, safe subset of expressions.

Formal Problem Statement

Implement evaluate_riddles(riddles: list[str]) -> list[bool].

Each riddle string has the form:

expect(<expr>).toBe(<expr>)

Where <expr> is one of:

  1. A string literal in double quotes, containing lowercase letters only: "abc"
  2. A non-negative integer literal: 0, 12, 300
  3. A function call with one argument: reverse(<expr>), len(<expr>), or isPalindrome(<expr>)

Supported functions:

  • reverse(s): returns the reversed string
  • len(s): returns the length of the string
  • isPalindrome(s): returns true if s equals its reverse, else false

Return a boolean per riddle indicating whether the left and right expressions evaluate to the same value (type-sensitive: string vs int vs bool).

Notes / Clarifications

  • Only the exact grammar above appears (no arithmetic, no concatenation, no variables).
  • true/false appear only as the output of isPalindrome(...) or as literals on the right/left.
  • Comparisons are strict: "2" is not equal to 2.

Constraints

  • 1 <= riddles.length <= 10^4
  • 1 <= riddles[i].length <= 200
  • Only lowercase a-z inside quotes
  • 0 <= integer <= 10^9 (fits in 32-bit signed)
  • Well-formed; no spaces; only reverse/len/isPalindrome and literals
Interviewer

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

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.