Affirm logo

Affirm

San Francisco, CAFintech

Interview Questions

File Parsing System

Asked at Affirm
technical
coding
system design

Design a file parsing system that reads, parses and filters file contents.

Example Data:

color    date        number
green    2001/02/23  8
purple   2006/05/11  1
white    2019/02/17  200

Sample Usage:

sheet = SpreadSheet("a.txt") 
sheet.filter(['color', '=', 'green']) # returns [['green', '2001/02/23', 8]]

Note: Colors may have duplicates.

Implement RandomizedSet Class

Asked at Affirm
technical
data structures
algorithms

Design a RandomizedSet class with O(1) average time complexity for all operations.

Required Methods:

  • RandomizedSet(): Initialize the object
  • bool insert(int val): Insert if not present, return true if inserted
  • bool remove(int val): Remove if present, return true if removed
  • int getRandom(): Get random element with equal probability

Follow-up: Modify the implementation to allow duplicates.

Share Your Experience at Affirm