Data Structures & AlgorithmsModerateTCS NQT · graph theory
Problem: Which is the time complexity of deciding whether an undirected graph has an Euler path?
- A. O(V^3)
- B. O(E^2)
- C. O(2^V)
- D. O(V + E)
Correct answer: D. O(V + E)
An Euler path exists iff the graph is connected (apart from isolated vertices) and has 0 or 2 odd-degree vertices, which takes linear time to check.
More Coding Interview Problems questions
- Problem: How many pairs (i, j) with 1 <= i < j <= 20 satisfy i j ≡ 1 (mod 7)? Run the code. python print(sum(1 for i in range(1, 21) for j…
- Problem: What is the smallest n such that n! exceeds 10^10? Run the code. python import math n = 1 while math.factorial(n) <= 10 10: n +=…
- Problem: What is the sum of the lengths of all subarrays of an array of length 6? Run the code. python n = 6 print(sum(i (n - i + 1) for i…
- Problem: What is the longest run of consecutive 1 bits in the binary representation of 1000? Run the code. python x = 1000 best = cur = 0…
- Problem: How many ways are there to make 15 from unlimited coins of value 1, 5 and 10 (order does not matter)? Run the DP. python ways =…
- Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code. python print(sum(1 for x in range(1…