Squares of a Sorted Array
Reported by candidates from Stryker's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Negative numbers are what break the lazy answer on this Stryker OA, reported in July 2026. Squares of a sorted array looks like a warm-up. Square everything, sort, done. That passes the examples, but it's O(n log n) when the input is already sorted and a linear answer exists. The pattern is two pointers on an array. The largest square is always at one of the two ends. If you freeze on the pointer logic, StealthCoder runs invisibly during the live assessment as a safety net, so one blank moment doesn't sink you.
The problem
Given an integer array nums sorted in nondecreasing order, square every value and return the resulting values in nondecreasing order. Function sortedSquares(nums: int[]) → int[] Examples Example 1 nums = [-4,-1,0,3,10] return = [0,1,9,16,100] Example 2 nums = [-7,-3,2,3,11] return = [4,9,9,49,121]
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: the input is sorted, but squaring flips the order for negatives. -4 becomes 16, which beats 3 squared. So the biggest square sits at the left end or the right end, never the middle. Put one pointer at index 0 and one at the last index. Compare absolute values, write the larger square into the result from the back, and move that pointer inward. Allocate a result array of the same length and fill it right to left. The common pitfall is filling left to right and hunting for the smallest, which sends you toward the middle and gets messy. Another one: forgetting that all-negative or all-positive arrays still work with this method. Check duplicates like Example 2, where 9 appears twice. If your pointer logic stalls mid-assessment, StealthCoder is the hedge that hands you the working version.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Squares of a Sorted Array 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as squares of a sorted array. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Stryker's OA.
Stryker reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Squares of a Sorted Array FAQ
What's the trick in Squares of a Sorted Array?+
Squares are largest at the extremes because negatives become big positives. Use two pointers at both ends, compare absolute values, and place the larger square at the back of the result. Move that pointer inward and repeat. It runs in O(n) time with O(n) output space.
Is sorting after squaring acceptable?+
It's correct, and it will pass the examples. But it's O(n log n) and ignores that the input is already sorted. If the Stryker OA has large inputs or you want the clean answer, write the two-pointer version. It's only a few more lines.
How hard is this problem really?+
Easy. The logic is short once you see the extremes idea. Most mistakes come from index handling, like filling the result in the wrong direction or moving the wrong pointer. Walk through Example 1 by hand before you submit.
What edge cases should I test?+
Test an all-negative array, an all-positive array, a single element, zeros, and duplicates after squaring such as -3 and 3. Example 2 already includes a tie at 9. Ties should work fine with either pointer moving, as long as you move exactly one per step.
How do I prepare for this in 48 hours?+
Write the two-pointer solution from scratch twice without looking. Then write the fill-from-the-back version on a blank editor. Spend the rest of your time on other array and two-pointer problems, since this pattern shows up often in short OAs.