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
Range Queries on Arrays
00:00
5 left

Range Queries on Arrays

MediumSQL · PostgreSQL

Problem

Given two arrays, Array1 (a multidimensional array) and Queries array (contains an array of L, R of many queries) ... do a certain operation from L(left index) to R (right index) in a given array and return the array of answers for all the queries.

Asked in the Coding Round stage. For this SQL version, the operation is an inclusive range sum over stored array positions.

Output

  1. Return query_id and range_sum, one row per query.
  2. Include queries with no matching positions, returning a sum of 0.
  3. Order by query_id ascending.

Schema

array1_values
ColumnTypeDescription
positionPKINTZero-based position in Array1
element_valueINTInteger value stored at the array position
range_queries
ColumnTypeDescription
query_idPKINTIdentifier and output order for the range query
left_indexINTInclusive left boundary
right_indexINTInclusive right boundary
Tablesarray1_valuesrange_queries
Interviewer

Your question is Range Queries on Arrays. Start with the requirements and the two tables 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.