Samsara logo

Samsara

San Francisco, CAIoT

Interview Questions

Meeting Time Overlap Counter

Asked at Samsara
technical
intervals
arrays

Count ongoing meetings at given time points.

Part 1: Single Time Point

interface Meeting {
  start: number;
  end: number;
}

function countOngoingMeetings(
  meetings: Meeting[],
  timePoint: number
): number

Example:
meetings = [[1,4], [2,5], [3,6]]
timePoint = 3
Output: 3 (all meetings overlap at t=3)

Part 2: Multiple Time Points

function countMeetingsAtTimes(
  meetings: Meeting[],
  timePoints: number[]
): number[]

Example:
meetings = [[1,4], [2,5], [3,6]]
timePoints = [1,3,7]
Output: [1,3,0]

Approach:
1. Sort meetings by time
2. Track active meetings
3. Binary search optimization

Merge Overlapping Intervals

Asked at Samsara
technical
intervals
sorting

Merge all overlapping intervals into non-overlapping intervals.

function mergeIntervals(
  intervals: number[][]
): number[][]

Example:
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]

Requirements:
- Sort intervals by start time
- Handle complete overlaps
- Merge partial overlaps
- Return minimal set

Time Complexity: O(n log n)
Space Complexity: O(n)

LRU Cache Implementation

Asked at Samsara
technical
data structures
design

Implement Least Recently Used (LRU) cache.

class LRUCache {
  constructor(capacity: number);
  get(key: number): number;
  put(key: number, value: number): void;
}

Requirements:
1. Data Structures
- HashMap for O(1) lookup
- Doubly linked list for order
- Fixed capacity

2. Operations
- get: Retrieve and update order
- put: Insert/update and maintain capacity
- Both O(1) time complexity

Example:
cache = new LRUCache(2)
cache.put(1, 1)    // cache is {1=1}
cache.put(2, 2)    // cache is {1=1, 2=2}
cache.get(1)       // return 1
cache.put(3, 3)    // LRU key was 2, cache is {1=1, 3=3}

Set Game Implementation

Asked at Samsara
technical
game design
object-oriented

Implement Set card game classes and logic.

enum Symbol { OVAL, SQUIGGLE, DIAMOND }
enum Shading { SOLID, STRIPED, OPEN }
enum Color { RED, GREEN, PURPLE }

class SetCard {
  constructor(
    symbol: Symbol,
    shading: Shading,
    color: Color
  );
}

class SetGame {
  constructor();
  dealCards(count: number): SetCard[];
  
  private createDeck(): SetCard[];
  private shuffleDeck(): void;
}

Requirements:
1. Card Properties
- Symbol (3 types)
- Shading (3 types)
- Color (3 types)

2. Game Setup
- Generate all combinations
- Random card dealing
- Maintain deck state

Example Usage:
const game = new SetGame();
const tableCards = game.dealCards(12);

Share Your Experience at Samsara