Interview conceptCoding & Algorithms

Numerical Coding And Algorithmic Data Processing

Asked of: Data Scientist

Last updated

What's being tested

These problems test algorithmic data-processing patterns a Data Scientist must use in production analytics: building n-gram frequency maps, one-pass streaming scans, efficient frequency counting, and string/sequence normalization. Interviewers probe correctness, algorithmic complexity (time/space), and pragmatic choices for edge cases and large inputs.

Patterns & templates

  • Sliding window / two-pointer scans for contiguous segments — single O(n) pass, maintain counts/lengths with deque or indices; watch inclusive/exclusive bounds.
  • Hash-map frequency: use collections.Counter or defaultdict(int) to build context→counts for n-grams and anagram multiset checks, O(n+m) time.
  • Stable deduplication: keep a set of seen keys and append unseen items to output list for order-preserving removal, O(n) time, O(n) extra memory.
  • Unicode normalization: apply unicodedata.normalize('NFKC', s) and .casefold() before comparing or counting characters to avoid locale surprises.
  • Large-index Fibonacci: use fast doubling or matrix exponentiation (O(log n)), apply modular arithmetic early for bounded results to avoid big-integer blowup.
  • N-gram predictor template: nested dict context -> Counter(next_word), store counts and optionally compute MLE probabilities or add-k smoothing for unseen-next handling.

Common pitfalls

Pitfall: Sorting strings to test anagrams is simpler but O(m log m) per string; counting characters is linear and scales better.

Pitfall: Off-by-one errors when converting inclusive time gaps into window boundaries cause wrong streak lengths in single-pass scans.

Pitfall: Forgetting Unicode normalization or .casefold() will make identical-looking tokens compare unequal in real text data.

Practice these

The practice cards below cover the canonical variants — solve all of them and time yourself.

Practice questions

Related concepts