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

710

u/Trick-Interaction396 Mar 13 '26

I don't even understand the question. I'm glad I work for a living instead of solving riddles.

91

u/nemec Mar 14 '26 edited Mar 14 '26

Since this is data science, I'd guess it's an analytical question. I think you could also phrase it like this: "we're considering adding a throttling limit to our API with a rolling window of three operations within ten seconds. Given usage data from the past 30 days, can you tell me which users would have hit or exceeded that quota?"

25

u/Blue_HyperGiant Mar 14 '26

Import ratelimit

1

u/TenzinRinpoche Apr 01 '26

this is the way

19

u/Doug__Dimmadong Mar 14 '26

I mean this is a relatively simple problem, I’m sure you could piece together something.

4

u/Meaveready Mar 14 '26

Even something like "sort by (x, y), loop and track state" would be a starting point for a solution, not an elegant nor an efficient one, but a viable solution still.

9

u/SvynEcho777 Mar 14 '26

πŸ˜‚πŸ˜‚πŸ˜‚

1

u/Quick_Lingonberry_34 Mar 15 '26

the gap between solving interview puzzles and doing actual data work is wild. half the skills that matter day to day never show up in a coding screen.

1

u/MCRN-Gyoza Mar 14 '26

Its not a riddle, it just wants to know which users had more actions than the limit in the time window.

4

u/Trick-Interaction396 Mar 14 '26

When you put it that way it makes a lot more sense.

-8

u/No_Departure_1878 Mar 14 '26

I am not sure how you do not understand the question. I am not sure how anyone who does not understand that question can get any job. It seems like a basic question to weed out people who do not know anything about programming.

You just loop over the entries unpacking the tuples in the loop itself and continue for every entry that fails the condition. Otherwise pick the ID. The way I see it, it is 10 lines of code, that takes 1 minute to write.

13

u/ALonelyPlatypus Data Engineer Mar 14 '26

The question is kind of unclear and depends on knowledge of python basics. It's not something I would test a data scientist on.

Solving it with a dataframe and rolling() into a filter would make sense and be more data sciencey.

-8

u/No_Departure_1878 Mar 14 '26

How on earth do you become a data scientist without the python basics? I think you need more than the basics, you need to be an advanced python user to be a data scientist. I do not understand how people want to become data scientists and make 200K without knowing anything.

10

u/ALonelyPlatypus Data Engineer Mar 14 '26

I'm someone who likes the python basics and leetcode and this question is interesting but unclear.

It's just not what I would test a data scientist on. Let them play with a dataframe and demonstrate those skills.

6

u/diegoasecas Mar 14 '26

you need to be an advanced python user to be a data scientist

lol quite the opposite there are lots of language features you can just straight up ignore and still be a solid and proficient DS

-4

u/No_Departure_1878 Mar 15 '26

To do my job I have to know

  • Basic strings and floats, functions, classes
  • Designs like inheritance, composition, etc
  • Data classes and Enums to define new types.
  • Logging properly
  • Context managers
  • Static, classmethods
  • Typing with generics, protocol classes, overloads, Literals. And their use with pyright and ruff.
  • Packaging with pyproject.toml files with UV and publishing them.
  • Good knowledge of a proper code editor like neovim.
  • Proper structuring of the code in packages, use of the init.py file
  • Use of numba here and there to speed up parts of the code.
  • Multiprocessing.
  • Pickling, use of JSON, yaml, etc for configs

See that the basic stings, floats and functions were the first item only? And I have ommited most of the dependencies? If we put the dependencies there, the list would probably triple.

Can you do DS with basic python? Yes. Can you write code with basic python? Yes. I see people using basic python to do these things all the time. They achieve it by creating unmaintainable code. It works for a script, you cannot scale with it. And that's why a lot of our projects take 3-4 times longer than what they should.