Data Structures & AlgorithmsHardGATE CS
In the grid 01210 / 11111 / 11121 / 01111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its fresh 4-neighbours. After how many minutes are no fresh oranges left?
- A. 5
- B. 2
- C. 6
- D. 3
Correct answer: D. 3
This is a multi-source BFS: put ALL rotten cells in the queue at time 0; the answer is the largest BFS distance to a fresh cell, 3. Running BFS from one rotten orange only overstates it.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A binary tree with distinct labels has INORDER E D I C A G H B F and LEVEL-ORDER I D H E G B C F A. What is its postorder traversal?
- The boolean expression F & T | T & T (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…
- What is the maximum flow from S to T in the network with directed capacities A→C (5), B→A (10), B→C (13), B→T (9), C→T (12), S→A (14), S→B…
- The boolean expression F & F & T ^ T (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…
- Keys 60, 41, 30, 69, 50, 54, 52, 55, 21 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- The weighted undirected graph A–B (1), A–C (6), A–E (3), B–D (1), C–D (2), C–E (5), D–E (3) has repeated weights. How many different…