Data Structures & AlgorithmsHardTCS NQT Digital · Infosys
Problem: A lucky 4-digit ticket has the sum of its first two digits equal to the sum of its last two digits. Each ticket number runs from 0000 to 9999 (leading zeros allowed). How many tickets are lucky?
- A. 100
- B. 615
- C. 670
- D. 385
Correct answer: C. 670
If N(s) two-digit pairs (00-99) have digit sum s, the lucky count is Σ N(s)² = 670 over s = 0..18. Adding N(s) instead of squaring gives 100, forbidding a leading zero gives 615, and stopping at s = 9 gives Σ (s + 1)² = 385.
More Coding Interview Problems questions
- Problem: A grid of 5×5 cells has 'X' blocked cells at (0,2), (1,2), (2,2), (3,2) (row, column, 0-indexed); the rest are open. Cells…
- Problem: On a grid, a diagonal step costs 2 and a straight step costs 1 (moves are up, down, left, right, and the four diagonals). What is…
- Problem: The cycle graph C8 has vertices 0–7 with i adjacent to (i+1) mod 8. How many unordered pairs of vertices are at distance exactly…
- Problem: A height-balanced binary search tree is built over the sorted keys 1, 2, …, 10 by always taking the middle element as the root…
- Problem: Given the parent array p = [−1, 0, 0, 1, 1, 2, 4, 4] for nodes 0–7 (node 0 is the root), how many nodes have exactly one child?
- Problem: A binary tree in level order (None for absent nodes) is [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]. How many root-to-leaf…