Memory-Heavy Pods

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
ESPN

Problem

The SRE team is profiling mid-range memory consumers across the Kubernetes cluster. Pull all unique pod names where memory usage falls between 100 and 500.

Memory-hungry workloads.

Tables

k8s_pods

Columns: pod_id INTEGER, pod_name TEXT, nspace TEXT, status TEXT, restarts INTEGER, cpu_used REAL, mem_used REAL

k8s_pods: 10 of 200 rows
pod_idpod_namenspacestatusrestartscpu_usedmem_used
2043payment-003efproductionPending00.01137
2086search-003f6stagingCrashLoopBackOff00.02274
2129gateway-003fdmonitoringCompleted00.033111
2172worker-00404kube-systemError00.044148
2215cron-0040bdefaultTerminating00.055185
2258ml-serve-00412productionRunning0NULLNULL
2301cache-00419stagingPending00.077259
2344auth-00420monitoringCrashLoopBackOff00.088296
2387payment-00427kube-systemCompleted00.099333
2430search-0042edefaultError00.11370

Expected output

First 5 of 9 rows
pod_name
gateway-003fd
worker-00404
cron-0040b
cache-00419
auth-00420

Worked solution and explanation

Why this problem exists in real interviews

The interviewer wants to see you apply query construction to k8s_pods.pod_name while accounting for the distribution of nspace. This surfaces as a fundamentals check because small logic errors produce results that look correct at a glance.


Break down the requirements

Step 1: Read from k8s_pods

The query targets k8s_pods with 7 columns. Identify which columns are needed for the output.

Step 2: Filter to the target rows

Use BETWEEN in the WHERE clause to select the target range. This is both readable and optimizable by the query planner.

Step 3: Return the result set

Select the required columns with any necessary aliasing or formatting.


The solution

BETWEEN range filter with DISTINCT
SELECT DISTINCT pod_name
FROM k8s_pods
WHERE mem_used BETWEEN 100 AND 500

Common follow-up questions