Online Assessment
First question: Perfect Substring
Given a string s made up only of digits, and an integer k, we need to find the number of substrings that satisfy a specific condition: every distinct digit character that appears in the substring must appear exactly k times.
- Input: string s and integer k
- Output: the total count of substrings satisfying the condition
- Example: if s = "11020211" and k = 2, the substrings "11" ('1' appears 2 times) and "0202" ('0' and '2' each appear 2 times) both satisfy the condition
Second question: Connected Groups
Given an N x N matrix related representing a relationship network. If related[i][j] is '1', it means entity i and entity j are directly connected; if it's '0', they are not directly connected.
The connection relationship is transitive, meaning if A is connected to B, and B is connected to C, then A, B, and C belong to the same group.
- The task is to compute how many disjoint connected components (groups) exist in the entire network
- This is a classic graph connected-components problem, which can be solved using DFS, BFS, or Union-Find
Discussion
Loading comments…