Floor Square Roots for an Array
Reported by candidates from Wells Fargo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Example 3 in this Wells Fargo OA, reported May 2025, is the whole point: 2147483647 goes in, 46340 comes out, and a sloppy 32-bit multiply will wreck you. The task is simple on paper. For each value in an array, return the largest integer r where r * r <= x. It's an array problem with a math core, and the trap is overflow, not logic. If you've got an invite and 48 hours, read this once. And if you blank during the live assessment, StealthCoder runs invisibly as a safety net and gives you the working solution.
The problem
Given an array of nonnegative integers values, return an array where result i is the floor square root of values[i]. For a number x, its floor square root is the largest integer r such that r * r <= x. Function floorSquareRoots(values: int[]) → int[] Examples Example 1 values = [0,1,4,9,16] return = [0,1,2,3,4] Every value is a perfect square. Example 2 values = [2,8,15,26] return = [1,2,3,5] Each result is rounded down to the largest integer whose square does not exceed the input. Example 3 values = [2147395600,2147483647] return = [46340,46340] Both values have floor square root 46340; multiplication must avoid 32-bit overflow. Constraints 1 <= values.length <= 10^5. 0 <= values[i] <= 2^31 - 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Two clean approaches. First, binary search per element: search r in [0, 46341], compare r * r to x using a 64-bit type. With 10^5 values and about 17 steps each, that's trivially fast. Second, call the built-in sqrt, cast to a long, then correct it with while loops: if r * r > x decrement, if (r+1)*(r+1) <= x increment. Floating point can be off by one near large perfect squares, so the correction step matters. The common pitfall is the overflow the problem warns about in Example 3. In Java or C++, use long for the multiply. In Python it's a non-issue, and math.isqrt does the whole job. Also handle x = 0 and x = 1 without special-casing weirdness. If the live OA freezes your brain on the bounds, StealthCoder is the hedge that hands you the binary search skeleton while you stay calm.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Floor Square Roots for an 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as sqrtx. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Wells Fargo's OA.
Wells Fargo reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Floor Square Roots for an Array FAQ
How hard is the Wells Fargo floor square roots problem really?+
Easy. It's a single pass over the array with a small per-element computation. The only real risk is integer overflow on values near 2^31 - 1. If you use a 64-bit type for the multiplication, you've handled the one thing that trips people up.
What's the trick to avoid overflow?+
Cast to long before multiplying, so r * r is computed in 64 bits. The max answer is 46340, and 46341 squared exceeds 2^31 - 1. Binary search with an upper bound of 46341 and long arithmetic keeps everything safe.
Can I just use the built-in sqrt function?+
Mostly, but don't trust it blindly. Floating point can round wrong near large perfect squares. Cast the result to a long, then adjust down if r * r > x or up if (r+1)*(r+1) <= x. In Python, math.isqrt is exact and skips all of this.
What's the time complexity I should aim for?+
Binary search per element gives O(n log M), where M is about 46341, so roughly 17 steps per value. With up to 10^5 values that's plenty fast. A sqrt plus correction approach is O(n). Either one passes the stated constraints.
How do I prepare for this in 48 hours?+
Write binary search for integer square root once from memory, using long for the multiply. Test it on 0, 1, 2, 2147395600 and 2147483647. Then skim similar array transform problems. That's enough, because the pattern is a single loop with a tiny helper.