Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: In a 3-row Pascal-like grid, a cell holds the number of ways to reach it moving only right or down from (0,0), with a blocked cell at (1,1). What is the number of ways to reach (2,2)?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Grid path counting with a blocked cell: the blocked cell contributes zero to every cell that would have used it. Forgetting to zero it gives the unobstructed count of 6.
More Coding Interview Problems questions
- Problem: Using Dijkstra from node 0 on the undirected graph with edges (0,1,2), (1,2,2), (0,2,5), (2,3,1), how many nodes have shortest…
- Problem: How many simple paths go from 0 to 3 in the undirected graph with edges 0-1, 1-2, 2-3, 3-0 and the chord 0-2? Run the DFS code…
- Problem: How many ordered pairs (a, b) with 1 <= a <= b <= 20 have gcd(a, b) = 1? Run the code. python from math import gcd print(sum(1…
- Problem: How many integers in [1, 100] are the product of exactly two distinct primes? Run the code. python def primesupto(n): s = [True]…
- Problem: What is the minimum length of a contiguous subarray of [1, 2, 3, 4, 5, 6, 7, 8] with sum at least 15? Run the two-pointer code…
- Problem: What is the integer floor of the square root of 10^12? Use binary search. python lo, hi = 0, 10 12 while lo < hi: mid = (lo + hi…