Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE
Problem: Vertices 1–6 of an undirected graph have edges 1-2, 2-3, 4-5, 5-6, 6-4 and 3-1. How many edges are NOT part of any cycle?
- A. 1
- B. 0
- C. 2
- D. 3
Correct answer: B. 0
An edge lies on a cycle exactly when removing it does not disconnect its endpoints. Here the two triangles 1-2-3 and 4-5-6 have all their edges on cycles, so the count of edges on no cycle is zero.
More Coding Interview Problems questions
- Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?
- Problem: The string "mississippi" contains repeated substrings. What is the length of the longest substring that appears at least twice…
- Problem: For the string "abcabcdab", how many substrings of length 3 occur exactly once?
- Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?
- Problem: The dynamic array doubles its capacity whenever it is full, starting from capacity 1. After inserting 9 elements one by one, how…
- Problem: In a binary heap stored in an array with 1-based indexing, the array [1, 3, 2, 7, 4, 5, 6] is a valid min-heap. What is the sum…