FastPrepNums That Are Divisible by N πŸ‹
Problems/Nums That Are Divisible by N πŸ‹

Nums That Are Divisible by N πŸ‹

Two Sigma logoTwo Sigma● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged task matches the visible source at about 99%. The sample array and 64-bit return type follow the source.

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[]) β†’ long

Examples

Example 1

N = 3arr = [1,2,3,4,5]return = 4

There are four valid pairs:

  • arr[0] + arr[1] = 1 + 2 = 3
  • arr[0] + arr[4] = 1 + 5 = 6
  • arr[1] + arr[3] = 2 + 4 = 6
  • arr[3] + arr[4] = 4 + 5 = 9

Each sum is divisible by 3, so the function returns 4.

Constraints

  • 1 <= arr.length <= 10^5
  • 1 <= arr[i] <= 10^9
  • 1 <= 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
All Two Sigma interview questionsSee Two Sigma hiring insights
Saved
class Solution {
    public long sumBeingAbletoBeDivisibleByN(int N, int[] arr) {
        // write your code here
    }

}
Checking account…