Sum of Divisors of the Array GCD
Updated
Problem statement
Given a nonempty array of positive integers values, compute the greatest common divisor of all values.
Return the sum of every positive divisor of that GCD.
Function
sumDivisorsOfArrayGcd(values: int[]) → longExamples
Example 1
values = [6,12,18]return = 12The array GCD is 6. Its positive divisors are 1, 2, 3, 6, whose sum is 12.
Example 2
values = [7,14]return = 8The GCD is 7, so the divisor sum is 1 + 7 = 8.
Example 3
values = [8,16,32]return = 15The GCD is 8. Its divisors 1, 2, 4, 8 sum to 15.
Constraints
1 <= values.length <= 2000001 <= values[i] <= 10^9- The answer fits in a signed 64-bit integer.
More Zscaler interview questions
- Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
- Merging PalindromesPHONE SCREEN · Seen Sep 2024
- Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
- Merge IntervalsPHONE SCREEN · Seen Jun 2024
- Asteroid CollisionONSITE INTERVIEW · Seen Sep 2024
- Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
- Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
- Longest Common Subsequence LengthONSITE INTERVIEW · Seen Jun 2024
- Run-Length EncodingONSITE INTERVIEW · Seen Jun 2024
- How Many Sentences? 🌿OA · Seen Mar 2024
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREEN
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Length of a Document Reached Through a Random TokenMercor · PHONE SCREEN
- Apply Affine Array TransformationsByteDance · PHONE SCREEN
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- One-Nearest-Neighbor Classification with Manhattan DistanceOpenAI · PHONE SCREEN
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Average Grades per StudentHartford Financial Services · PHONE SCREEN
- Through-Origin Linear RegressionMeta · PHONE SCREEN
- Latency Bucket CounterDatadog · OA · PHONE SCREEN