Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 C
Problem: A functional graph has n = 9 nodes where node i points to f(i) given by the list [1, 2, 0, 4, 5, 3, 3, 6, 7] (node i has exactly one outgoing edge to f(i)). How many nodes lie on cycles?
- A. 9
- B. 2
- C. 6
- D. 3
Correct answer: C. 6
Following f from every node finds the cycles 0 → 1 → 2 → 0 and 3 → 4 → 5 → 3; nodes 8 → 7 → 6 form a tail that drains into node 3, so 6 nodes lie on cycles. Assuming every node of a functional graph is on a cycle gives 9, counting cycles gives 2, and counting tail nodes gives 3.
More Coding Interview Problems questions
- Problem: Matrix chain multiplication: the dimensions of three matrices are given by the array p = [10, 30, 5, 60], meaning A1 is 10×30, A2…
- Problem: Maximum profit with at most two buy-sell transactions (one stock, you must sell before buying again) for the daily prices [3, 3…
- Problem: How many pairs i < j in the array [2, 8, 9, 18, 4, 32, 50, 72] have a product a[i] × a[j] that is a perfect square?
- Problem: How many three-digit numbers (100 to 999) have strictly increasing digits from left to right (for example 147 qualifies, 151 does…
- Array a = [1, 2, 3, 4, -1, 5, 0, 2]. How many contiguous subarrays have a sum of exactly 10?
- Array a = [2, -2, 3, -3, 4, -4, 1]. How many DISTINCT values appear among the prefix sums P[0], P[1], ..., P[7] (including P[0] = 0)?