PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Implement LRU cache and prime products array

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in implementing efficient mutable data structures and in enumerating combinatorial results, specifically testing understanding of LRU cache eviction behavior and generation of all non-empty subset products from a set of primes.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Implement LRU cache and prime products array

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given two separate coding tasks. ### Task 1: Implement an LRU cache Implement an in-memory cache with a fixed capacity that evicts the least recently used (LRU) key when the capacity is exceeded. Implement the following operations: - `get(key)`: return the value associated with `key` if present; otherwise return -1. - `put(key, value)`: insert or update the value for `key`. If the cache exceeds its capacity after this operation, evict the least recently used key. Both operations must run in average O(1) time. Assume keys and values are integers. The cache capacity is a positive integer given at construction time. ### Task 2: Generate products from an array of primes You are given an array `primes` of distinct prime integers, length `n` where `1 <= n <= 15` and each value is in the range `[2, 10^6]`. Return a sorted list (ascending order) containing all unique products that can be formed by taking the product of any non-empty subset of `primes`. Each prime can be used at most once in a product (that is, you are considering subsets, not multisets). Example: - Input: `primes = [2, 3, 11]` - All non-empty subsets and their products: - `[2]` -> 2 - `[3]` -> 3 - `[11]` -> 11 - `[2, 3]` -> 6 - `[2, 11]` -> 22 - `[3, 11]` -> 33 - `[2, 3, 11]` -> 66 - Output: `[2, 3, 6, 11, 22, 33, 66]`

Quick Answer: This question evaluates proficiency in implementing efficient mutable data structures and in enumerating combinatorial results, specifically testing understanding of LRU cache eviction behavior and generation of all non-empty subset products from a set of primes.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Oct 28, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
6
0

You are given two separate coding tasks.

Task 1: Implement an LRU cache

Implement an in-memory cache with a fixed capacity that evicts the least recently used (LRU) key when the capacity is exceeded.

Implement the following operations:

  • get(key) : return the value associated with key if present; otherwise return -1.
  • put(key, value) : insert or update the value for key . If the cache exceeds its capacity after this operation, evict the least recently used key.

Both operations must run in average O(1) time.

Assume keys and values are integers. The cache capacity is a positive integer given at construction time.

Task 2: Generate products from an array of primes

You are given an array primes of distinct prime integers, length n where 1 <= n <= 15 and each value is in the range [2, 10^6].

Return a sorted list (ascending order) containing all unique products that can be formed by taking the product of any non-empty subset of primes. Each prime can be used at most once in a product (that is, you are considering subsets, not multisets).

Example:

  • Input: primes = [2, 3, 11]
  • All non-empty subsets and their products:
    • [2] -> 2
    • [3] -> 3
    • [11] -> 11
    • [2, 3] -> 6
    • [2, 11] -> 22
    • [3, 11] -> 33
    • [2, 3, 11] -> 66
  • Output: [2, 3, 6, 11, 22, 33, 66]

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.