Python
All Top 50 Python & Pandas Interview Questions#48
Implement SQL LAG and LEAD with .shift() in Pandas
EasyFlipkartInterview Question #48
Asked at FlipkartGiven user page visits with timestamps, calculate the time elapsed since the previous visit for each user.
Input Table: user_visits
3 rows preview| user_id | visit_time |
|---|---|
| 101 | 2026-03-01 10:00:00 |
| 101 | 2026-03-01 10:25:00 |
| 102 | 2026-03-01 11:00:00 |
Expected Output Structure2 rows
| user_id | visit_time | elapsed_min |
|---|---|---|
| 101 | 2026-03-01 10:00:00 | NULL |
| 101 | 2026-03-01 10:25:00 | 25 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Click "Run & Test" to execute your Pandas code against the test assertions.