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
SQL and Simple Coding Problem
00:00
5 left

SQL and Simple Coding Problem

HardSQL · PostgreSQL

Problem

How do you find the second largest maximum of an unsorted array by linear scanning? How do you check if a number is a power of 2 in the smallest time in Python 3?

Represent array elements and numbers to check as SQL tables. Return the second-largest distinct non-null value for each array and a power-of-two result for every input number.

Output

  1. Columns: result_type, array_id, second_largest, number_value, is_power_of_two
  2. Include one row per array result and one row per number check.
  3. Sort array results by array_id, followed by number checks by number_value, with NULL last.

Schema

array_elements
ColumnTypeDescription
element_idPKINTUnique element row identifier
array_idINTIdentifier of the logical array
element_positionINTOriginal position of the element
element_valueBIGINTNumeric array element
power_checks
ColumnTypeDescription
check_idPKINTUnique power-check identifier
number_valueBIGINTNumber to classify as a power of two
Tablesarray_elementspower_checks
Interviewer

Your question is SQL and Simple Coding Problem. 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.