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
Key Alive in Time Range (SQL)
00:00
5 left

Key Alive in Time Range (SQL)

HardSQL · PostgreSQL

Problem

Confluent Cloud operations needs to determine which API keys were alive during a requested interval. An API key is considered alive during the half-open interval from an ACTIVE event until the next lifecycle event, including an open-ended interval when no later event exists.

Write a PostgreSQL query that returns every registered key with at least one active interval overlapping the requested range.

Requirements

  1. Use LEAD to determine when each lifecycle interval ends.
  2. Treat intervals as half-open, [start, end), so an activation exactly at the range end does not qualify.
  3. Return the overlapping portion of each active interval, including multiple qualifying intervals for one key.
  4. Order results by key_id and the beginning of the overlap.

Schema

api_keys
ColumnTypeDescription
key_idPKINTRegistered API key identifier
key_nameVARCHAR(100)Human-readable API key name
owner_teamVARCHAR(100)Owning Confluent team
key_events
ColumnTypeDescription
event_idPKINTLifecycle event identifier
key_idINTReferences api_keys.key_id
effective_atTIMESTAMPTZTime the resulting state became effective
state_afterVARCHAR(20)State after the event
event_noteTEXTOptional operational note
time_ranges
ColumnTypeDescription
range_idPKINTRequested range identifier
range_nameVARCHAR(100)Description of the requested range
range_startTIMESTAMPTZInclusive range start
range_endTIMESTAMPTZExclusive range end
Tablesapi_keyskey_eventstime_ranges
Interviewer

Your question is Key Alive in Time Range (SQL). Start with the requirements and the three 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.