Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate JavaScript Riddle Assertions

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

Your question is Validate JavaScript Riddle Assertions. 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

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
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output