Reported September 2024
Amazongreedy

Find Days S2 Subsequence of S1

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's subsequence matching problem shows up when they want to see if you can track state across two strings efficiently. You're looking at a problem where you need to find how many days it takes to match a pattern string within a larger string, consuming characters sequentially without backtracking. This is a two-pointer or greedy pattern in disguise. StealthCoder can spot the approach instantly if you blank on how to iterate through both strings in one pass.

Pattern and pitfall

The core trick is greedy iteration. You maintain a pointer in the pattern string and scan through the days string, advancing the pattern pointer only when you find a matching character. Once you match all characters in the pattern, you record the day count and reset. Most candidates overthink this with dynamic programming or try to use substring search. The problem is really asking: given a sequence of daily strings, how many complete days do you need to form your target pattern by consuming characters greedily. A single pass with two pointers and a day counter is all you need. StealthCoder's hedge here is recognizing that 'matching a subsequence across timesteps' is fundamentally a stateful greedy walk, not a complex DP problem.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Find Days S2 Subsequence of S1 cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as is subsequence. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Days S2 Subsequence of S1 FAQ

Is this a sliding window problem?+

No. Sliding window works when you're looking for a contiguous substring or fixed-size window. This is greedy two-pointer. You walk through the days string once, greedily match characters in the pattern, and count days until the pattern is exhausted.

Do I need to reset the pattern pointer after each day?+

That depends on the exact problem statement, but typically yes. After each day, if you've matched the full pattern, you reset and record the day number. If not, you carry forward the progress into the next day.

What's the time complexity?+

O(n*m) in the worst case, where n is the total length of all days concatenated and m is the pattern length. Single pass through each character per pattern completion keeps it linear in practice.

Can I use regex or string.find()?+

You could, but you'd miss the point. The problem tests your ability to manually iterate and track state. Building the two-pointer solution shows you understand the greedy logic Amazon is testing.

What if the pattern can't be matched?+

Return an empty list or -1, depending on the return type. The problem will specify. Common edge case: always validate that every character in the pattern exists somewhere in the days data before returning a result.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it