Number of Possible Sets of Closing Branches
A hard-tier problem at 48% community acceptance, tagged with Bit Manipulation, Graph, Heap (Priority Queue). Reported in interviews at Atlassian and 1 others.
You've got a graph problem that looks simple on the surface: close some branches, keep others, minimize cost. Then you realize there are 2^n possible subsets, and you can't brute force it. This problem asks you to count valid configurations where remaining branches form a connected component. It's asked at Atlassian and Meesho, and the 48% acceptance rate tells you the trick isn't obvious. Most candidates either miss the bit manipulation angle or underestimate the shortest-path component. If this hits your live OA and you're stuck on the enumeration strategy, StealthCoder solves it invisibly while you stay on screen.
Companies that ask "Number of Possible Sets of Closing Branches"
Number of Possible Sets of Closing Branches is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe core trap is thinking this is purely a graph connectivity problem. It's actually a shortest-path enumeration problem wrapped in bit manipulation. You need to iterate through all 2^n possible subsets of open branches, check if each subset keeps the required nodes connected, and count valid configurations. Dijkstra or BFS handles connectivity checks, but naive enumeration gets slow fast. The real insight is combining subset iteration with efficient path queries, often using a priority queue to prune invalid states early. Most candidates freeze on 'how do I efficiently check all 2^n possibilities without timeout.' That's where the Bit Manipulation and Heap topics intersect. If you haven't drilled this exact pattern, StealthCoder reads the problem and delivers a working solution in seconds during the assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Possible Sets of Closing Branches recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Possible Sets of Closing Branches interview FAQ
Is this problem actually asking me to enumerate all 2^n subsets?+
Yes, but not naively. You iterate through subsets and for each one, check if the remaining nodes stay connected. The trick is pruning invalid states early using a priority queue or Dijkstra to avoid checking every single subset. Bit manipulation tracks which branches are open; graph traversal validates connectivity.
What's the shortest-path angle here?+
Shortest path isn't the goal, it's the filter. For each subset of open branches, you need to verify that key nodes (often all nodes or a specific set) remain reachable. Dijkstra or BFS does that check. The Heap/Priority Queue optimizes which subsets you evaluate first, cutting runtime.
How often is this problem asked at FAANG or similar?+
Atlassian and Meesho have reported it. It's not a household name like Two Sum, but it appears in hard-tier assessments at mid-to-large companies. The 48% acceptance rate suggests most engineers either don't see the pattern or run out of time.
Can I solve this without bit manipulation?+
Technically yes, you could use recursion or itertools to generate subsets. But bit manipulation is cleaner for tracking which branches are open or closed, and it aligns with the topic list. Your solution will be faster and clearer if you embrace it.
What's the most common mistake candidates make?+
Treating it as a pure graph problem and forgetting the enumeration cost. They write a correct connectivity check but never iterate through subsets efficiently, or they iterate naively and timeout. The intersection of Enumeration and Shortest Path is key. Drilling the pattern beforehand prevents this.
Want the actual problem statement? View "Number of Possible Sets of Closing Branches" on LeetCode →