← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Apr 2026Remote

Summary

Snowflake coding round with a weighted interval scheduling problem. Not the typical course schedule DAG thing you'd expect, which threw me off a bit at first.

Questions Asked (1)

Q1

Given a list of courses each with a start time, end time, and credit value, and a maximum number K of courses you can take, find the maximum total credits you can earn from at most K non-overlapping courses.

Algorithms & Data Structures
Author's notes

I went in expecting the classic DAG prerequisite version and had to mentally reset when I saw the interval constraints.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a weighted interval scheduling problem with a cardinality constraint (at most K courses). First, sort courses by end time and use dynamic programming where dp[i][k] represents the maximum credits using the first i courses with at most k selections. For each course, either skip it or take it and combine with the best compatible previous course, using binary search to find the latest non-overlapping course.

Pro tip: Clarify whether courses can be taken back-to-back (end time equals start time) and whether K can exceed the number of courses. Also, mention that if K is large (≥ number of courses), the problem reduces to the classic weighted interval scheduling without the cardinality constraint, which can be solved more efficiently.

1. Clarify assumptions and edge cases

Confirm whether intervals are half-open or closed, if K can be larger than the number of courses, and if courses with zero or negative credits exist. Discuss how these affect the solution.

2. Sort and preprocess

Sort the courses by end time. For each course, compute the index of the latest course that finishes before it starts (using binary search on end times). This enables efficient transition in DP.

3. Define DP state and recurrence

Let dp[i][k] be the maximum credits using the first i courses (sorted by end time) with at most k courses selected. Recurrence: dp[i][k] = max(dp[i-1][k], credits[i] + dp[p(i)][k-1]) where p(i) is the latest compatible course index.

4. Optimize space and time

Reduce space to O(K) by iterating k from 1 to K and updating a 1D array. Time complexity is O(n log n + nK). If K is large, consider alternative approaches like min-cost max-flow or greedy with priority queue for special cases.

5. Analyze complexity and test

State time and space complexity. Walk through a small example to verify correctness, and discuss potential optimizations or trade-offs.

Key Points to Mention

  • Dynamic programming with state (index, remaining selections)
  • Sorting by end time and binary search for compatible intervals
  • Time complexity O(n log n + nK) and space O(K) after optimization
  • Handling edge cases: K >= n, overlapping intervals, zero/negative credits
  • Comparison with classic weighted interval scheduling (K unconstrained)
  • Potential alternative: min-cost max-flow or greedy for specific cases

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