Find All Pythagorean Triplets
Updated
Problem statement
Given an integer array nums, return every unique value triplet [a, b, c] that can be formed from three different array positions and satisfies a * a + b * b = c * c.
Output rules
- For this exercise, every input value is positive, so write each triplet with
a <= b < c. - Return each value triplet only once, even if several index selections produce it.
- Return the triplets in lexicographic order.
Function
findPythagoreanTriplets(nums: int[]) → int[][]Examples
Example 1
nums = [3,4,5,6,8,10]return = [[3,4,5],[6,8,10]]Both rows satisfy the square-sum equality and are already in lexicographic order.
Example 2
nums = [5,12,13,3,4,5,5]return = [[3,4,5],[5,12,13]]Repeated values may create the same value triplet through several positions, but that row is returned once.
Constraints
0 <= nums.length <= 2000.1 <= nums[i] <= 10^7.
More Dell Technologies interview questions
Similar questions at other companies
- Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Valid Triangle NumberBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- 3SumAmazon · PHONE SCREEN
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
- Adaptive Calibration ErrorOpenAI · PHONE SCREENOpenAI interview questions
- Meeting Rooms IIUber · PHONE SCREENUber interview questions
- Sort ColorsVisa · PHONE SCREENVisa interview questions