PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Snowflake

Solve three coding rounds

Last updated: Apr 19, 2026

Quick Overview

This multi-part question evaluates algorithmic problem-solving and practical implementation skills, covering grid geometry and distance metrics for nearest-item queries, expression parsing and nested evaluation for a command-based calculator, and time-indexed data structure design for versioned key-value storage in the Coding & Algorithms domain.

  • medium
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Solve three coding rounds

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given three independent interview-style coding tasks. ## 1) Nearest cake/person in a 2D grid You are given an `m x n` grid of integers: - `1` = cake - `0` = person Assume at least one cake and at least one person exist. ### 1A. Minimum distance between any cake and any person Compute the minimum Manhattan distance between any person cell and any cake cell. - Manhattan distance between `(r1,c1)` and `(r2,c2)` is `|r1-r2| + |c1-c2|`. - **Output:** an integer minimum distance. ### 1B. Which cake does a given person eat? Each person will eat the **closest** cake (by Manhattan distance). You are given the position (or index) of one specific person, and you must return which cake that person will eat. Additional guarantees: 1. For any fixed person, there is no tie between their closest cakes. 2. For any fixed cake, there is no tie between its closest people. These guarantees imply the assignment is deterministic (no ambiguous choices). - **Input:** the grid and a target person location `(rp, cp)` (known to be a `0`). - **Output:** the cake location `(rc, cc)` that this person eats. ## 2) Implement a simple command-based calculator You are given a list of strings `commands`, each command being one of: - `"ADD x"` - `"SUB x"` - `"MULT x"` - `"DIV x"` where `x` is an integer (may be negative). Start with an accumulator value `acc = 0`. Process commands in order, updating `acc` each time. `DIV` should use truncation toward zero (like integer division in many languages). - **Output:** the final `acc` after all commands. ### Follow-up (nested computation) Extend the calculator to support nested expressions inside a command, e.g. operands can themselves be expressions, such as: - `"ADD (MULT 3 (ADD 2 5))"` Define a clear grammar and evaluate the expression correctly. ## 3) Design an in-memory time-indexed key-value store Implement an in-memory store supporting: - `set(key, value, timestamp)` - `get(key, timestamp)` → returns the value associated with `key` at the greatest timestamp `t'` such that `t' <= timestamp`. If none exists, return an empty value. Assume: - `key` and `value` are strings - `timestamp` is an integer - Multiple values can be set for the same key at different timestamps You should design data structures and implement these operations efficiently.

Quick Answer: This multi-part question evaluates algorithmic problem-solving and practical implementation skills, covering grid geometry and distance metrics for nearest-item queries, expression parsing and nested evaluation for a command-based calculator, and time-indexed data structure design for versioned key-value storage in the Coding & Algorithms domain.

Related Interview Questions

  • Solve Array Distance and Wiki Navigation - Snowflake (medium)
  • Implement Document Predicate APIs - Snowflake (medium)
  • Find Shortest Wiki Click Path - Snowflake (medium)
  • Schedule prerequisite classes with retakes - Snowflake (easy)
  • Minimize coins with overpay and change - Snowflake (hard)
Snowflake logo
Snowflake
Mar 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
16
0
Coding Console
Loading...

You are given three independent interview-style coding tasks.

1) Nearest cake/person in a 2D grid

You are given an m x n grid of integers:

  • 1 = cake
  • 0 = person

Assume at least one cake and at least one person exist.

1A. Minimum distance between any cake and any person

Compute the minimum Manhattan distance between any person cell and any cake cell.

  • Manhattan distance between (r1,c1) and (r2,c2) is |r1-r2| + |c1-c2| .
  • Output: an integer minimum distance.

1B. Which cake does a given person eat?

Each person will eat the closest cake (by Manhattan distance). You are given the position (or index) of one specific person, and you must return which cake that person will eat.

Additional guarantees:

  1. For any fixed person, there is no tie between their closest cakes.
  2. For any fixed cake, there is no tie between its closest people.

These guarantees imply the assignment is deterministic (no ambiguous choices).

  • Input: the grid and a target person location (rp, cp) (known to be a 0 ).
  • Output: the cake location (rc, cc) that this person eats.

2) Implement a simple command-based calculator

You are given a list of strings commands, each command being one of:

  • "ADD x"
  • "SUB x"
  • "MULT x"
  • "DIV x"

where x is an integer (may be negative).

Start with an accumulator value acc = 0. Process commands in order, updating acc each time. DIV should use truncation toward zero (like integer division in many languages).

  • Output: the final acc after all commands.

Follow-up (nested computation)

Extend the calculator to support nested expressions inside a command, e.g. operands can themselves be expressions, such as:

  • "ADD (MULT 3 (ADD 2 5))"

Define a clear grammar and evaluate the expression correctly.

3) Design an in-memory time-indexed key-value store

Implement an in-memory store supporting:

  • set(key, value, timestamp)
  • get(key, timestamp) → returns the value associated with key at the greatest timestamp t' such that t' <= timestamp . If none exists, return an empty value.

Assume:

  • key and value are strings
  • timestamp is an integer
  • Multiple values can be set for the same key at different timestamps

You should design data structures and implement these operations efficiently.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snowflake•More Software Engineer•Snowflake Software Engineer•Snowflake 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.