Connected Components with Divisor Threshold
Updated
Problem statement
Given integers n and t, consider an undirected graph with nodes labeled 1 through n.
An edge exists between two distinct nodes i and j if and only if gcd(i, j) > t.
Return an array [componentCount, largestComponentSize], where componentCount is the total number of connected components and largestComponentSize is the number of nodes in the largest component.
Function
analyzeDivisorComponents(n: int, t: int) → int[]Examples
Example 1
n = 6t = 2return = [5,2]Nodes 3 and 6 are connected because gcd(3, 6) = 3 > 2. Every other node is isolated, so there are 5 components and the largest has size 2.
Example 2
n = 5t = 0return = [1,5]The greatest common divisor of every pair of positive labels is greater than 0, so the graph is connected.
Example 3
n = 4t = 4return = [4,1]No pair has a greatest common divisor greater than 4. All four nodes are isolated.
Constraints
1 ≤ n ≤ 200,0000 ≤ t ≤ n
More InMobi Online Assessment questions
- Validate a Bracket SequenceOA · Seen Oct 2026
- Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
- Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
- Minimum Service Cold StartsOA · Seen Oct 2026
- Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
- Maximize Impression ValueOA · Seen Aug 2026
- Supply Path OptimizationOA · Seen Aug 2026
- Delivery ServiceOA · Seen Jun 2026
- Shared InterestOA · Seen Jun 2026
- Temporal AnomaliesOA · Seen Jun 2026
Similar questions at other companies
- Connected SumAtlassian · OAAtlassian interview questions
- Count Components With a Prime Total ValueNutanix · ONSITE INTERVIEWNutanix interview questions
- Minimum Unreachable WarehousesVisa · OAVisa interview questions
- Doctor Appointment Slot AssignmentDRW · OADRW interview questions
- Visible Profiles CountMicrosoft · OAMicrosoft interview questions
- TikTok Server Network OptimizationTikTok · OATikTok interview questions
- Can Sort Permutation in Given MovesAmazon · OA
- Get Node To RemoveSalesforce · OASalesforce interview questions
- Number of Good PairsCommvault · OACommvault interview questions
- Process Queries to Find Critical NodesCisco · OACisco interview questions