Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

Leetcode #2092: Find All People With Secret

In this guide, we solve Leetcode #2092 Find All People With Secret in Python and focus on the core idea that makes the solution efficient.

You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Leetcode

Problem Statement

You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei.

Quick Facts

  • Difficulty: Hard
  • Premium: No
  • Tags: Depth-First Search, Breadth-First Search, Union Find, Graph, Sorting

Intuition

The data forms a graph, so we should explore nodes and edges systematically.

A traversal ensures we visit each node once while maintaining the needed state.

Approach

Build an adjacency list and traverse with BFS or DFS.

Aggregate results as you visit nodes.

Steps:

  • Build the graph.
  • Traverse with BFS/DFS.
  • Accumulate the required output.

Example

Input: n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1 Output: [0,1,2,3,5] Explanation: At time 0, person 0 shares the secret with person 1. At time 5, person 1 shares the secret with person 2. At time 8, person 2 shares the secret with person 3. At time 10, person 1 shares the secret with person 5.​​​​ Thus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.

Python Solution

class Solution: def findAllPeople( self, n: int, meetings: List[List[int]], firstPerson: int ) -> List[int]: vis = [False] * n vis[0] = vis[firstPerson] = True meetings.sort(key=lambda x: x[2]) i, m = 0, len(meetings) while i < m: j = i while j + 1 < m and meetings[j + 1][2] == meetings[i][2]: j += 1 s = set() g = defaultdict(list) for x, y, _ in meetings[i : j + 1]: g[x].append(y) g[y].append(x) s.update([x, y]) q = deque([u for u in s if vis[u]]) while q: u = q.popleft() for v in g[u]: if not vis[v]: vis[v] = True q.append(v) i = j + 1 return [i for i, v in enumerate(vis) if v]

Complexity

The time complexity is O(m×log⁡m+n)O(m \times \log m + n)O(m×logm+n), and the space complexity is O(n)O(n)O(n), where mmm and nnn are the number of meetings and the number of experts, respectively. The space complexity is O(n)O(n)O(n), where mmm and nnn are the number of meetings and the number of experts, respectively.

Edge Cases and Pitfalls

Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.

Summary

This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.


Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2026 Stealth Interview®Stealth Interview is a registered trademark. All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy