Hi everyone,
Today I had the opportunity to appear for Amazon’s SDE II Online Assessment.
Honestly, this was way harder than what I expected. I was literally staring at the screen for an hour and still couldn’t figure out the problem statements. These were nothing like standard textbook LeetCode problems where you can directly apply 2-pointers, heaps, sliding window, or classical DP.
Here are the 2 questions I faced:
Q1. Sequence Construction
Given integers n and target, construct a sequence of length n such that:
Among all valid sequences, return the lexicographically smallest.
Input: n=4, target=-2
Valid sequences:
[-1, -2, -3, 4]
[ 3, -2, 1, -4]
[-4, -2, 1, 3] <-- lexicographically smallest
Output: [-4, -2, 1, 3]
Q2. String Expansion with !
You are given a string consisting of characters '0', '1', and '!'.
Return the minimum possible count over all expansions, modulo 1e9+7.
Example: s => "0!1!"
Ouptut: 3
Explanation:
There are 2^2 = 4 expansions (replace each ! by 0 or 1):
total subsequences = 3
(explicit: "01" = 2 pairs, "10" = 1 pair)
total subsequences = 4
(explicit: "01" = 4, "10" = 0)
total subsequences =4
(explicit: "01" = 2, "10" = 2)
total subsequences = 3
(explicit: "01" = 3, "10" = 0)
Minimum total over all expansions = 3.
This was my first time appearing for such an OA, and honestly, I didn’t expect the difficulty to be this high.
Does anyone have suggestions or advice on how to prepare better for such non-standard problems in the future?
Thanks in advance 🙏