MEDIUMasked at 4 companies

Valid Triangle Number

A medium-tier problem at 52% community acceptance, tagged with Array, Two Pointers, Binary Search. Reported in interviews at Expedia and 3 others.

Founder's read

Valid Triangle Number is a medium-difficulty array problem that Expedia, LinkedIn, Bloomberg, and Nvidia have all asked in their technical assessments. You're given an array of integers and need to count how many combinations of three numbers can form a valid triangle. It sounds straightforward until you realize brute force times out and the trick isn't obvious. The acceptance rate sits around 52%, which means roughly half the candidates who attempt it either time out or miss the greedy insight. If this problem hits your live OA and you blank on the pattern, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
4
Difficulty
MEDIUM
Acceptance
52%

Companies that ask "Valid Triangle Number"

If this hits your live OA

Valid Triangle Number is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.

Get StealthCoder
What this means

The naive approach is to check every triplet, but that's O(n^3) and too slow. The key insight is sorting first, then using two pointers. For any three sides to form a valid triangle, the sum of the two smaller sides must be strictly greater than the largest side. Once sorted, you can fix the largest side and shrink a two-pointer window from the left. If a pair works, all pairs between them work too (greedy property). This drops complexity to O(n^2). Most candidates either don't sort or don't realize the two-pointer optimization cuts the search space dramatically. The binary search and greedy topics in the classification hint at the algorithmic flexibility here. StealthCoder is your hedge if you arrive at the assessment without practicing the sorted-plus-two-pointer pattern.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Valid Triangle Number recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Valid Triangle Number interview FAQ

Why doesn't brute force work here?+

Checking every triplet is O(n^3). On an array of size 1000 or 2000, that's billions of operations, which times out. The sorted two-pointer approach runs O(n^2), which passes comfortably. Acceptance rate of 52% suggests many candidates hit that timeout wall.

What's the actual trick to solving this?+

Sort the array, then fix the largest side and use two pointers on the remaining elements. If nums[left] + nums[mid] > nums[right], all pairs between left and mid also satisfy the triangle inequality. Move the pointers accordingly. It's a greedy collapse that avoids redundant checks.

Is this still asked at LinkedIn and Bloomberg?+

Yes. Bloomberg, LinkedIn, Expedia, and Nvidia have all reportedly asked it. It's a classic medium that tests whether you understand sorting and pointer optimization, not just basic array iteration. It's a strong signal of intermediate problem-solving.

How does Two Pointers relate to this problem?+

Two pointers is the core technique after sorting. You fix one pointer at the largest side, then converge from left and right on the smaller elements. If the triangle condition fails, you move inward. It's why Two Pointers is listed as a topic.

What's a common mistake?+

Not sorting first, or sorting but not using two pointers and falling back to O(n^3) logic. Another mistake is off-by-one errors with the inequality direction. The condition is nums[left] + nums[mid] > nums[right], not greater-than-or-equal.

Want the actual problem statement? View "Valid Triangle Number" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.