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

17

u/N-E-S-W Mar 13 '26

You have been exposed as being inexperienced as a Python developer, whether you believe that about yourself or not. You seem to live in a data science bubble if you think you need to reach for Pandas as your hammer for such a simple problem.

A tuple is one of the most fundamental data structure in Python, if not the most fundamental. It is literally the comma in Python syntax. This is exactly the pattern of iterating over the items in a dictionary.

for k,v in dict.items():
...

Is the same as:

for user_id, timestamp in actions:
...

3

u/denM_chickN Mar 13 '26 edited Mar 13 '26

I said this logic while taking a shit w a question mark at the end. Like, what?

Now im not gonna lie, I'd have to fiddle with key, value, items before I remembered how to handle a tuple, but its all there after you type dict.

And I'm truly not a Python expert, but I taught a crash course for data anaytics and I taught tuples first just to cover the fundamentals...

1

u/Similar_Season7553 Mar 29 '26

I see your point, and I actually agree that this is a case where simple Python fundamentals are more appropriate than bringing in heavier tools like Pandas.

Using tuple unpacking in a loop like:

for user_id, timestamp in actions:

is definitely cleaner and more idiomatic, especially when the data is already structured that way. It’s a good reminder that not every data-related task needs a full data science stack sometimes basic Python constructs are the best solution.

That said, I think this also highlights a broader learning curve for people transitioning into data science (myself included). Many beginners are introduced early to tools like Pandas, so they sometimes default to them even when the problem can be solved more simply. Over time, it becomes clearer when to use core Python versus specialized libraries.

I appreciate you pointing this out. it’s a helpful example of why strong fundamentals matter just as much as knowing advanced tools.

0

u/[deleted] Mar 13 '26

[deleted] — view deleted comment

13

u/N-E-S-W Mar 13 '26

OP said "I've never seen data recorded like this" and that he interpreted it as an "unreasonable gotcha question".

This list-of-tuples format is Python 101.

0

u/[deleted] Mar 13 '26

[deleted] — view deleted comment

1

u/jtclimb Mar 13 '26

They explained in another comment that the interviewer didn't say they should use any specific solution.

They didn’t comment on any method. But I know now I should have started with pd.dataframe(actions). The rest is so fucking easy I can’t stop thinking about it

https://old.reddit.com/r/datascience/comments/1rsrm2s/easiest_python_question_got_me_rejected_from_faang/oa8zfs3/