Maximum Difference
Updated
Problem statement
Given a set of nodes and a set of edges between pairs of nodes, first identify the connected components in the graph. A connected component is a group of nodes that are all linked, either directly or through other nodes in the group.
For each connected component, calculate the difference between its largest and smallest node values, and return the maximum of these differences.
Function
maximumDifference(g_nodes: int, g_from: int[], g_to: int[]) → int Complete the function maximumDifference in the editor below.
maximumDifference has the following parameters:
int g_nodes: the number of nodes in the graphint g_from[g_edges]: one endpoint of each edgeint g_to[g_edges]: the other endpoint of each edge
- Returns:
int: the maximum difference between the largest and smallest node value within any connected component
Examples
Example 1
g_nodes = 4g_from = [1, 2]g_to = [2, 3]return = 2Nodes 1, 2, and 3 form one connected component, whose difference is 3 - 1 = 2. Node 4 is isolated, so its component difference is 0. The maximum difference is 2.
Example 2
g_nodes = 6g_from = [1, 2, 4]g_to = [2, 3, 6]return = 2The connected components are {1, 2, 3}, {4, 6}, and {5}. Their differences are 2, 2, and 0, so the result is 2.
Example 3
g_nodes = 5g_from = [1, 4]g_to = [5, 2]return = 4The components are {1, 5}, {2, 4}, and {3}. Their differences are 4, 2, and 0, so the maximum difference is 4.
Constraints
1 ≤ g_nodes ≤ 1051 ≤ g_edges ≤ min(105, (g_nodes × (g_nodes - 1)) / 2)
More Akuna Capital Online Assessment questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
Similar questions at other companies
- Connected GroupsVisa · OAVisa interview questions
- Visible Profiles CountIBM · OAIBM interview questions
- Disaster RecoveryHeadlands Technologies · OAHeadlands Technologies interview questions
- Minimum Cost to Supply Water with Wells and PipesInfosys · OAInfosys interview questions
- Recoverable Elements from Range-Sum MeasurementsEthos Life · OA
- Connected Components with Divisor ThresholdInMobi · OAInMobi interview questions
- Doctor Appointment Slot AssignmentDRW · OADRW interview questions
- Biggest Connected ComponentCodeium · OACodeium interview questions
- Visible Profiles CountMicrosoft · OAMicrosoft interview questions
- TikTok Server Network OptimizationTikTok · OATikTok interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)