← PayPal Interview Insights

PayPal·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

First-round Python screen for a Data Scientist role at PayPal. Pretty straightforward coding task but I overthought parts of it and the sorting tripped me up a bit.

Questions Asked (1)

Q1

Write a function in plain Python (no libraries) that takes a list of strings and returns a dictionary of each unique word mapped to how often it appears. Then print the top three most frequent words in descending order.

Algorithms & Data Structures
Author's notes

Felt fine building the frequency dict with a for-loop, that part came naturally.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: define what constitutes a 'word' (e.g., case sensitivity, punctuation) and confirm that the output should be a dictionary and then the top three words printed. Then implement the solution using a dictionary to count frequencies, and finally sort the items by count in descending order to extract and print the top three.

Pro tip: Mention edge cases like empty input, ties in frequency, and words with different cases, and discuss how you would handle them (e.g., lowercasing, stable sorting). This shows attention to detail and production readiness.

1. Clarify requirements

Ask about word definition (case sensitivity, punctuation), input constraints, and expected output format. Confirm that ties should be handled consistently (e.g., alphabetical order).

2. Design the counting logic

Use a dictionary to iterate through the list of strings, splitting each string into words and updating counts. Consider preprocessing like lowercasing if appropriate.

3. Implement the function

Write the function in plain Python, ensuring it returns the frequency dictionary. Handle potential edge cases such as empty strings or non-string inputs if necessary.

4. Extract and print top three

Sort the dictionary items by count in descending order (and secondarily by word if needed) and print the first three. Use slicing and a loop or formatted output.

5. Test and discuss

Walk through test cases (e.g., empty list, single word, ties) to verify correctness. Discuss time and space complexity: O(n) time and O(k) space where k is unique words.

Key Points to Mention

  • Use of a dictionary (hash map) for O(1) average-time lookups and updates.
  • Time complexity: O(n) to count words, plus O(k log k) for sorting, where k is number of unique words.
  • Space complexity: O(k) for the dictionary and sorted list.
  • Handling ties in frequency: specify a secondary sort key (e.g., alphabetical) for deterministic output.
  • Edge cases: empty input, empty strings, punctuation, and case sensitivity.
  • Python-specific features: collections.Counter (though not allowed here, mention it as an alternative) and sorted() with key parameter.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.