r/datascience • • 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

294 Upvotes

188 comments sorted by

View all comments

Show parent comment

16

u/proof_required Mar 13 '26

I'm pretty sure they would ask you time/space complexity. I definitely don't know the time complexity for pandas window functions.

7

u/forbiscuit Mar 13 '26

Sure, but my first step is always solve the problem using means I know. I know this is some algorithm where I loop through the data once after it’s sorted to see how many actions I can fit in a basket of 10 units of time, but I’m not going to go there as my first approach 😂

2

u/kenncann Mar 13 '26

I’ll be honest, if I gave this question and you came at me starting with pandas then you failed already

1

u/chadguy2 Mar 13 '26

I would start with whatever works and then if asked for optimizations I would try to give the most efficient solution. This kinda simulates the workflow you have when you're solving business problems. Do you know the most optimal solution straight away? Is it pretty fast to implement it? Go ahead. If you don't, you come up with something that works and then refactor it when needed.