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
Binary Zeros Constraint
00:00
5 left

Binary Zeros Constraint

HardSQL · PostgreSQL

Problem

You call a number beautiful if it contains at least 1 bit '0' and at most 3 bits '0' in its binary representation.

Asked in the OA stage. For Q queries [L, R] up to 1e18, output the sum of cubes of beautiful numbers in range modulo 998244353. The input ranges are stored in query_ranges.

Output

  1. One row per valid query, with query_id and beautiful_cube_sum.
  2. Include values from the inclusive range [L, R]; exclude rows with NULL bounds.
  3. Order by query_id ascending.

Schema

query_ranges
ColumnTypeDescription
query_idPKINTUnique identifier for the range query
lower_boundNUMERIC(20,0)Inclusive lower bound of the queried range
upper_boundNUMERIC(20,0)Inclusive upper bound of the queried range
Tablesquery_ranges
Interviewer

Your question is Binary Zeros Constraint. Start with the requirements and the one table 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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.