Reported September 2026
Zomatounion find

Friend Circles and Redundant Connections

Reported by candidates from Zomato's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Zomato OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Zomato OA, reported in September 2026, is counting circles with a DFS and then guessing at redundant edges from the edge count. The task is clean. Given peopleCount and a list of friendships, return the number of connected components and the number of edges that closed a cycle. It's a union-find problem wearing a social-network costume. If you blank on the structure during the live assessment, StealthCoder is the silent hedge that reads the problem and hands you the approach. But the pattern is small enough to own tonight.

The problem

People are labeled from 0 through peopleCount - 1. Each undirected friendship joins two people.
Return [circleCount, redundantEdgeCount], where a friend circle is a connected component and an edge is redundant when its endpoints were already connected by earlier edges. Isolated people count as circles.

Function
countCirclesAndRedundantEdges(peopleCount: int, friendships: int[][]) → int[]

Examples
Example 1
peopleCount = 5
friendships = [[0,1],[2,3],[3,4]]
return = [2,0]
Case 1 exercises the documented deterministic contract.
Example 2
peopleCount = 3
friendships = [[0,1],[1,2],[0,2]]
return = [1,1]
Case 2 exercises the documented deterministic contract.
Example 3
peopleCount = 4
friendships = []
return = [4,0]
Case 3 exercises the documented deterministic contract.

Constraints
1 <= peopleCount <= 200000.
0 <= friendships.length <= 200000.
Endpoints are valid labels and self-edges are permitted.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Use union-find with path compression and union by size. Start with circleCount = peopleCount and redundant = 0. For each edge, find both roots. If the roots match, increment redundant. If they differ, union them and decrement circleCount. That's it. The pitfall is the self-edge. An edge like [2,2] has equal roots immediately, so it counts as redundant, and the same logic handles it with no special case. Another trap is duplicate edges, which are also redundant because the endpoints were already connected. Don't compute redundant as edges minus (people minus circles) unless you trust that identity. It does hold, but processing in order is safer. With 200000 people and 200000 edges, skip recursive DFS in languages with shallow stacks, and write find iteratively. If the live OA freezes your memory of the template, StealthCoder is there as the safety net.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Friend Circles and Redundant Connections cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as redundant connection. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Zomato's OA.

Zomato reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Friend Circles and Redundant Connections FAQ

What's the trick in the Zomato friend circles problem?+

Union-find. Start with every person as their own circle. For each friendship, if both endpoints share a root, it's redundant. If not, merge them and drop the circle count by one. One pass, near-linear time.

How are self-edges handled?+

A self-edge like [3,3] has the same root on both sides, so the find check marks it redundant automatically. No special branch needed. The problem statement explicitly permits them, so test one before you submit.

Can I solve it with DFS or BFS instead?+

You can count components with DFS or BFS, but redundant edges are awkward because the order of edges matters in the definition. Union-find processes edges in order and answers both numbers in the same loop, so it's cleaner.

Do duplicate friendships count as redundant?+

Yes. If [0,1] appears twice, the second one finds both people already connected, so it's redundant. Union-find counts it correctly without extra bookkeeping or a set of seen edges.

How do I prepare for this in 48 hours?+

Write a union-find class from memory with iterative find, path compression, and union by size. Then run the three examples, including the empty friendships case returning [4,0]. Twenty minutes of reps is enough for this one.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Zomato.

OA at Zomato?
Invisible during screen share
Get it