← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Snowflake SWE interview with a greedy optimization problem that looks straightforward but has a few wrinkles worth thinking through carefully.

Questions Asked (1)

Q1

You manage a virtual data warehouse with n query types, each with a fixed runtime and a per-run revenue. You have K total minutes and must pick exactly one query type to run repeatedly. How do you maximize total revenue, and which query type do you choose?

Algorithms & Data StructuresPricing & Monetization
Author's notes

My first instinct was to sort by revenue and just pick the highest one, which is wrong.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

For each query type, compute the maximum number of times it can run within K minutes (floor(K / runtime_i)) and multiply by its per-run revenue to get total revenue. Then select the query type with the highest total revenue. This is an O(n) scan, and you should discuss edge cases like zero runtime or zero revenue.

Pro tip: Mention that this is a classic fractional knapsack variant where the constraint forces choosing exactly one item type, so the greedy choice by total revenue is optimal. Also, clarify that if runtimes don't divide K evenly, leftover time is wasted, which can affect the choice.

1. Understand the problem

Restate the problem: you have K minutes, n query types each with fixed runtime and revenue per run, and you must pick exactly one type to run repeatedly. The goal is to maximize total revenue.

2. Define the computation

For each query type i, calculate the number of runs as floor(K / runtime_i) and total revenue as runs * revenue_i. Note that any leftover time cannot be used.

3. Compare and select

Iterate through all query types, compute total revenue for each, and keep track of the maximum. Return the query type that yields the maximum revenue.

4. Analyze complexity and edge cases

The algorithm runs in O(n) time and O(1) extra space. Discuss edge cases: runtime > K (zero runs), zero revenue, zero runtime (infinite runs, but likely invalid), and ties.

5. Optimize if needed

If the problem allows, consider precomputing or using a priority queue for dynamic updates, but for a single query, the linear scan is optimal.

Key Points to Mention

  • The problem is a variant of the knapsack problem where you must choose exactly one item type, making it simpler.
  • Total revenue for a query type is floor(K / runtime) * revenue_per_run.
  • The optimal strategy is to compute total revenue for each type and pick the maximum.
  • Time complexity is O(n) and space complexity is O(1).
  • Edge cases: runtime greater than K, zero revenue, zero runtime, and ties.
  • Leftover time cannot be used for other queries, so it's wasted.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.