Pair Up an Array So Every Pair Sum Divides by k
Updated
Problem statement
You are given an integer array nums with an even number of elements, and an integer k. Group all the elements in twos: every element goes into exactly one pair, so the pairs use up the whole array.
Return true if the pairs can be chosen so that the sum of every pair is divisible by k, and false otherwise. A sum may be negative or zero; for example, -6 and 0 are both divisible by 3.
Function
canPairUp(nums: int[], k: int) → booleanExamples
Example 1
nums = [7,-3,5,11,2,-2]k = 4return = trueOne way: 7 + (-3) = 4, 5 + 11 = 16 and 2 + (-2) = 0. All three sums are divisible by 4.
Example 2
nums = [5,9,2,6]k = 5return = false5 is divisible by 5, so its partner must be divisible by 5 too, and no other value is. So no pairing works.
Example 3
nums = [-1,1]k = 7return = trueThe only pair sums to 0, and 0 is divisible by every k.
Constraints
2 <= nums.length <= 10^4, andnums.lengthis even.-10^9 <= nums[i] <= 10^91 <= k <= 10^5
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
- Filter Paginated Medical RecordsNVIDIA · PHONE SCREENNVIDIA interview questions
- Count Product-Divisible PairsMotive · PHONE SCREENMotive interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Max Points on a LineUber · PHONE SCREENUber interview questions
- Average Grades per StudentHartford Financial Services · PHONE SCREENHartford Financial Services interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
Interview reports that mention this question
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 ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
- Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)