EasyFundamentals
Surge Pricing Driver Eligibility
Frequently Asked By:AppleGoogleAmazon
Interactive In-Browser Workspace
Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.
Problem Statement
Find all qualifying drivers in `driver_profiles` who:
- Are currently online (`is_online = true`)
- Have vehicle tier in `'XL'` or `'Black'`
- Have a driver `rating` of at least **4.85**
- Have completed at least **100** `lifetime_trips`
Return:
1. `driver_id`
2. `driver_name`
3. `vehicle_tier`
4. `rating`
5. `lifetime_trips`
Order results by `rating` descending, then by `lifetime_trips` descending.
Why Technical Interviewers Ask This
During peak hours, QuickRide activates a 2.5x surge pricing multiplier. Only active online drivers in premium vehicle classes ('XL' and 'Black') who maintain a rating of 4.85 or higher and have at least 100 completed trips qualify for priority dispatch.
Common Pitfalls & Interview Traps
Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass fundamentals constructs.
Canonical Modern SQL Solution
PostgreSQL 16 / ANSI SQLSELECT
driver_id,
driver_name,
vehicle_tier,
rating,
lifetime_trips
FROM driver_profiles
WHERE is_online = true
AND vehicle_tier IN ('XL', 'Black')
AND rating >= 4.85
AND lifetime_trips >= 100
ORDER BY rating DESC, lifetime_trips DESC;Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Fundamentals. It meets the target criteria: Online top-rated XL and Black tier drivers eligible for surge dispatch.Edge Cases to Verbally Clarify with Your Interviewer
The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.
Frequently Asked Follow-Up Questions
What makes this question a favorite among Apple and Google interviewers?
Interviewers use this problem to test whether candidates write defensive, scalable Fundamentals queries that run efficiently on multi-million row production databases without excessive memory usage.
How does the query optimizer execute this query?
Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.