FastPrepCount Triples That Can Form a Triangle
Problems/Count Triples That Can Form a Triangle

Count Triples That Can Form a Triangle

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You count how many ways three numbers from an array can be picked as the sides of a real triangle. An Adobe MTS2 report from India (a C++ role in Noida, rejected) names this task by its title and a link. The author had two years as an SDE I and wrote the post on the day of the interview in January 2024. It was the first of two questions in an hour-long first DSA round on an online coding site. A hard running-median question followed. The report adds nothing beyond the name.

The rules are those of the named task. Triples are picked by position, and a flat triple does not count. We chose these limits: up to 1000 values, from 0 to 10^6. We wrote new examples.

Our version is about 95% the same as the reported question.

Given an array nums of stick lengths, count the triples of positions i < j < k whose three lengths can be the sides of a triangle.

Three lengths form a triangle when the sum of any two of them is strictly greater than the third. A flat triple, where two lengths add up exactly to the third, does not count. Equal lengths at different positions are different sticks, so they give different triples.

Function

triangleCount(nums: int[]) → int

Examples

Example 1

nums = [6,4,9,3]return = 2

The triples are (6,4,9): 4 + 6 = 10 > 9, yes; (6,4,3): 3 + 4 = 7 > 6, yes; (6,9,3): 3 + 6 = 9, not greater than 9, no; (4,9,3): 3 + 4 = 7 < 9, no. Two triples work.

Example 2

nums = [5,5,5,5]return = 4

Any three of the four 5s make a triangle (5 + 5 > 5). There are 4 ways to choose 3 of 4 positions.

Example 3

nums = [0,1,1]return = 0

A side of length 0 can never be part of a triangle: 0 + 1 = 1 is not greater than 1.

Constraints

  • 1 <= nums.length <= 1000
  • 0 <= nums[i] <= 10^6

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Count Winning Dice Face PairsGoogle · PHONE SCREENGoogle interview questions
  • Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • 3SumAmazon · PHONE SCREEN
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
  • Meeting Rooms IIUber · PHONE SCREENUber interview questions
  • Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
  • Sort ColorsVisa · PHONE SCREENVisa interview questions

Interview reports that mention this question

  • Adobe MTS Interview Questions: 12 Experiences (Part 2 of 6)
  • Adobe Experienced Hire Interviews: 55 Experiences (Part 1 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int triangleCount(int[] nums) {
        // Write your code here.
    }
}
Checking account…