Valid Triangle Number
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an array nums of non-negative integers representing stick lengths. Count the number of index triples i < j < k whose three lengths can form a triangle with positive area, meaning the sum of any two of the lengths is strictly greater than the third.
Triples are counted by index, so equal lengths at different positions produce distinct triples.
Aim for O(n^2) time.
Examples
Constraints
- 1 <= nums.length <= 1000
- 0 <= nums[i] <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.