InterviewLegend

DP on Strings

Alex Chen20 min readUpdated 111 real interview reports

Each problem here reduces a string to a small state and builds it up one character at a time. Counting valid words with a cap on consecutive vowels only needs the length of the vowel run at the end. Two disjoint palindromic subsequences need a bitmask showing which indices the first one took. A Premium question needs two numbers, how far into the text and how far into the pattern you've matched.

The first two have come up on Snowflake's online assessment, and the third in a senior phone screen. On the assessment, hidden tests decide the score, so the constraint line at the bottom of each prompt matters more than the recurrence. With at most 12 characters, brute force over masks is the intended approach. Counts taken modulo 1e9 + 7 need the reduction on every multiply. And since a regex has to match the whole text, a search that stops at the first partial match is solving a different problem.

The Snowflake angle
Read the bottom of the prompt before the story at the top. Premium question looks like it needs an interval DP for two interleaved palindromes, but the 12-character cap means there are only 4,096 masks, and you can try them all. String Patterns looks like it needs a closed-form formula, but the modulus tells you to build the count one letter at a time. Snowflake's RLIKE is anchored at both ends, the same contract as is_match here, so say "whole value" before drawing the grid.

SnowflakePremium lesson · Coding round

The 3 Snowflake problems are below.

  1. A Premium questionCoding · Medium · Frequently asked
  2. A Premium questionCoding · Medium
  3. A Premium questionCoding · Hard

Each with hints, the follow-up and a tested solution.

Get the Snowflake questions

$49 a year · all 100 companies · cancel anytime

From 111 Snowflake reports, forum threads behind logins and write-ups in Chinese.

Had your Snowflake interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Snowflake interview guide

Know what Snowflake asks before you walk in.

31 coding · 5 system design · 18 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.