Find Max Number of Pairs
Updated
Problem statement
Given an array, find the numbers with the same number of digits that can form the largest number of different pairs. For example, given the array {1, 9, 23, 30, 54, 103}, the possible pairs are {1, 9}, {23, 30}, {23, 54}, and {30, 54}, and the output should be 4.
In other words: a pair is two different elements of nums that have the same number of digits. The pair {x, y} is the same as {y, x}. Count every such pair, adding up the pairs from all digit lengths. In the example, the 1-digit numbers give 1 pair, the 2-digit numbers give 3 pairs, and 103 has no partner, so the answer is 1 + 3 = 4.
Complete the function findMaxNumberOfPairs in the editor.
findMaxNumberOfPairs has the following parameter:
int[] nums: distinct positive integers
The function returns an int: the number of pairs of elements with the same number of digits.
Function
findMaxNumberOfPairs(nums: int[]) → intExamples
Example 1
nums = [1, 9, 23, 30, 54, 103]return = 4The pairs with the same number of digits are:
{1, 9}(1 digit each){23, 30},{23, 54},{30, 54}(2 digits each)
103 is the only 3-digit number, so it has no partner. There are 1 + 3 = 4 pairs, so the output is 4.
Constraints
1 ≤ nums.length ≤ 1041 ≤ nums[i] ≤ 109- All values in
numsare distinct.
More Roblox interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
- Centered Block Placement QueriesOA · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
Similar questions at other companies
- Next Pascal Row CoefficientIntuit · OA
- Subarray SumVisa · OA
- Get Triplet CountIBM · OA
- Sum of Pipeline Response TimesBloomberg LP · OA
- Get Triplet CountPoint72 · OA
- Product of Subset MaximaArcesium · OA
- Minimum Operations to Flip Exactly K BitsGoogle · OA
- Find Maximum Number of Balanced CombinationsAmazon · OA
- Counting Triplets Divisible by DAT&T · OA
- Count Valid TeamsWells Fargo · OA
Interview reports that mention this question
Roblox interview experiences
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)