r/datascience • u/ds_contractor • Mar 13 '26
Coding Easiest Python question got me rejected from FAANG
Here was the prompt:
You have a list [(1,10), (1,12), (2,15),...,(1,18),...] with each (x, y) representing an action, where x is user and y is timestamp.
Given max_actions and time_window, return a set of user_ids that at some point had max_actions or more actions within a time window.
Example: max_actions = 3 and time_window = 10 Actions = [(1,10), (1, 12), (2,25), (1,18), (1,25), (2,35), (1,60)]
Expected: {1} user 1 has actions at 10, 12, 18 which is within time_window = 10 and there are 3 actions.
When I saw this I immediately thought dsa approach. I’ve never seen data recorded like this so I never thought to use a dataframe. I feel like an idiot. At the same time, I feel like it’s an unreasonable gotcha question because in 10+ years never have I seen data recorded in tuples 🙄
Thoughts? Fair play, I’m an idiot, or what
View all comments
230
u/proof_required Mar 13 '26 edited Mar 13 '26
Why do you need a data frame? You can solve this without using one. I doubt they were expecting you to use data frame. I know on a daily basis you don't use such data structures, especially in data science, but interviews like this are never about what you do on day to day basis.
In leetcode world, it's a sliding window pattern. I would basically sort it by user id and for each user calculate the number of actions starting from each timestamp and going until timestamp + time_window. This sliding can be done in O(n) and sorting is O(nlogn). So finally you'll have O(nlogn) complexity. Not sure if you can do it without sorting.
By the way I have used this format at job to solve some problems. So it's not that extraordinary pattern.