2dbi

Most-frequent co-occurrence (Affirm's recurring problem)

viaLeetCode

Affirm's most frequently reported coding problem. It appears with three framings — letters in words, company names per record, or merchants per purchase history — but the algorithm is identical: given a list of records (each a set of items), for every item find the other item(s) that co-occur with it in the greatest number of records. Two items co-occur in a record if both appear in it; count each record at most once per pair and ignore duplicates within a record.

['abc', 'bcd', 'cde']
=>
{ a: [b, c], b: [c], c: [b, d], d: [c], e: [c, d] }

The company / merchant framing is the same, with words replaced by lists of names:

[['Casper','Purple','Wayfair'], ['Purple','Wayfair','Tradesy'], ['Wayfair','Tradesy','Peloton']]
=>
{ 'Casper': ['Purple','Wayfair'], 'Purple': ['Wayfair'], 'Wayfair': ['Purple','Tradesy'],
  'Tradesy': ['Wayfair'], 'Peloton': ['Wayfair','Tradesy'] }

Reported across phone screens from 2019 through 2023.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account