Count Elements With At Least One Smaller And One Greater Value
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Uber's July OA included a straightforward filtering problem that catches candidates off guard because it feels too simple. You're given an array and need to count how many elements have at least one smaller value and one larger value somewhere in that array. The trap is overthinking it. Most candidates write nested loops or over-engineer with sorting when the pattern is just a single pass to track the min and max, then another pass to count. StealthCoder will catch this if you blank on the approach under time pressure.
Pattern and pitfall
The core trick is two passes, no sorting needed. First pass: find the global minimum and maximum values in the array. Second pass: count elements that are strictly greater than the minimum and strictly less than the maximum. This skips the element itself naturally because if an element is the min or max, it won't satisfy both conditions. The common pitfall is trying to compare each element against every other element (O(n^2)) or sorting and losing the original indices. The pattern is simple filtering with a single global state check. StealthCoder flags this as a candidate moment where time pressure makes you second-guess a linear solution.
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 Count Elements With At Least One Smaller And One Greater Value 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
You've seen the question.
Make sure you actually pass Uber's OA.
Uber 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.
Count Elements With At Least One Smaller And One Greater Value FAQ
What if the array has duplicates?+
Duplicates don't matter. You're just checking if there exists any smaller and any larger value in the entire array. If the array is [1, 1, 1, 2, 3], the second 1 still counts because 2 and 3 exist. Min is 1, max is 3. Count all elements strictly between them.
Do I need to handle negative numbers differently?+
No. The min and max logic works the same. If the array is [-5, 0, 5], min is -5, max is 5. Count all elements strictly greater than -5 and strictly less than 5. That's 0 and everything else in between.
What if all elements are the same?+
The count is zero. If all elements equal X, then min = max = X. No element can be both greater than X and less than X. Edge case but straightforward.
Is this still asked after being on LeetCode?+
Yes. Uber's OA uses publicly known problems frequently. This is a real filter test, not a trick. Candidates who panic and over-code lose time. The pattern is array iteration plus comparison logic. It tests whether you can spot the simple solution under pressure.
How do I prepare for this in 48 hours?+
Know how to find min and max in a single pass. Practice recognizing when a problem is asking for a global property vs. element-by-element comparison. This problem teaches you not to default to nested loops. One loop to find bounds, one to count. Done in minutes.