Nums That Are Divisible by N π
Updated
Problem statement
Given an integer N and an integer array arr, count the ways to choose two different indices i and j such that i < j and arr[i] + arr[j] is divisible by N.
Return the number of valid index pairs as a long.
Function
sumBeingAbletoBeDivisibleByN(N: int, arr: int[]) β longExamples
Example 1
N = 3arr = [1,2,3,4,5]return = 4There are four valid pairs:
arr[0] + arr[1] = 1 + 2 = 3arr[0] + arr[4] = 1 + 5 = 6arr[1] + arr[3] = 2 + 4 = 6arr[3] + arr[4] = 4 + 5 = 9
Each sum is divisible by 3, so the function returns 4.
Constraints
1 <= arr.length <= 10^51 <= arr[i] <= 10^91 <= N <= 10^9
More Two Sigma interview questions
- IPO Share AllocationOA Β· Seen Sep 2026
- Sewer Drainage PartitionOA Β· Seen Sep 2026
- Daily Temperature By TownOA Β· Seen Sep 2026
- Linear InterpolatorOA Β· Seen Sep 2026
- Online No-Intercept Linear RegressionOA Β· Seen Sep 2026
- Balanced Split String with WildcardsOA Β· Seen Aug 2026
- Closest ColorOA Β· Seen Aug 2026
- Price-Time Order MatchingPHONE SCREEN Β· Seen Aug 2026
- Piecewise Linear Interpolation and ExtrapolationOA Β· Seen May 2026
- Calculate y/x using PatchOA Β· Seen Nov 2025
Similar questions at other companies
- Count Valid Square PairsAuxoAI Β· OA
- Basic Item DiscountsPalantir Β· OAPalantir interview questions
- Distinct Products After Removing One ElementHSBC Β· OAHSBC interview questions
- Find Max Sum with Same First and Last DigitMicrosoft Β· OAMicrosoft interview questions
- Stock PricesRubrik Β· OARubrik interview questions
- Get Max Discount PairsAmazon Β· OA
- Find Number of Interesting PairsThe D.E. Shaw Group Β· OAThe D.E. Shaw Group interview questions
- Find Mean and ModeCisco Β· OACisco interview questions
- Minimum Rounds to Complete All TasksInfosys Β· OAInfosys interview questions
- Get Triplet CountIBM Β· OAIBM interview questions