EASYasked at 2 companies

Check If It Is a Straight Line

A easy-tier problem at 40% community acceptance, tagged with Array, Math, Geometry. Reported in interviews at Palantir Technologies and 1 others.

Founder's read

Check If It Is a Straight Line shows up in screens at Palantir and Datadog, and it's deceptively simple. You're given coordinates and need to verify they're collinear. The trap: a 39% acceptance rate means most candidates either overthink the geometry or bust on edge cases. The obvious approach (compute slope) fails fast when you hit vertical lines or divide-by-zero. StealthCoder is the safety net if you blank on the math trick during your live assessment.

Companies asking
2
Difficulty
EASY
Acceptance
40%

Companies that ask "Check If It Is a Straight Line"

If this hits your live OA

Check If It Is a Straight Line 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 engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The core insight is slope comparison, but you can't divide to compute slopes without crashing on vertical lines. Instead, use the cross-product method: for three consecutive points, check if the area of the triangle they form is zero. Algebraically, (y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1). This avoids division entirely and handles all cases, including vertical and horizontal lines, with integer arithmetic. Most failures come from either attempting slope division or forgetting that all points must be collinear, not just checking pairs. The Array iteration is trivial once you nail the geometry formula. If you hit this during a live OA and can't recall the cross-product trick, StealthCoder solves it in seconds while staying invisible to the proctor.

Pattern tags

The honest play

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

Check If It Is a Straight Line recycles across companies for a reason. It's easy-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 engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Check If It Is a Straight Line interview FAQ

Why does a naive slope comparison fail?+

Vertical lines have undefined slope, causing division by zero. Horizontal lines work fine, but mixing line types breaks. The cross-product avoids division altogether and handles every case uniformly, including collinear points on axes.

Is this really asked at top companies?+

Yes. Palantir and Datadog both report asking it. At 39% acceptance, it's not rare but it's not trivial either. Most failures are logic errors, not algorithm choice.

What's the actual trick to solving this?+

Use the cross-product formula: (y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1). It's pure math, no calculus, and it works for every point triplet. Iterate through all points and verify the condition holds.

How does Geometry relate to Array iteration here?+

Array is just the loop. You iterate through points once, applying the geometric test to each triplet. The real work is the Math formula. Get that wrong and the iteration doesn't save you.

What edge cases kill most solutions?+

Vertical lines, duplicate points, and arrays with fewer than three points. If you're dividing to compute slope, you fail immediately on vertical lines. Integer overflow is rare but possible with large coordinates.

Want the actual problem statement? View "Check If It Is a Straight Line" 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.