Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Counting Bits in Arrays
00:00
5 left

Counting Bits in Arrays

EasySQL · PostgreSQL

Problem

Count the number of 0s and 1s in a binary array.

Use the binary_array table. Count only valid binary values, excluding NULL entries.

Output

  1. One row per valid bit value.
  2. Columns: bit and bit_count.
  3. Return values in ascending order of bit.

Schema

binary_array
ColumnTypeDescription
positionPKINTPosition of the value in the binary array
bitINTBinary array value, expected to be 0 or 1
Tablesbinary_array
Interviewer

Your question is Counting Bits in Arrays. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.