Feature #4: Maximum Routers
Implementing the "Maximum Routers" feature for our "Network" project.
We'll cover the following
Description
We have several routers interconnected in a rectangular grid. Each router has an ID, and all router IDs are stored in a 2D array. Any router may forward a packet to any of its neighbors above it, below it, to its right or left, in the array, if the neighbor’s ID is higher than its own. We have an important packet that can be injected into any single router in the network. The goal is to have the packet forwarded to as many routers in the network as possible. No router should receive the packet more than once.
We’ll be provided with an m x n
matrix containing the IDs for each router.
Our task will be to forward the packet to the maximum number of routers.
Let’s try to understand this better with an illustration:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.