TV Tower Expansion
Updated
Problem statement
You are given a rectangular binary matrix city. A cell with value 1 initially contains a TV tower, and a cell with value 0 does not.
Each day, every cell containing a tower installs towers in its orthogonally adjacent cells: up, down, left, and right, when those cells are inside the matrix.
Return the number of days required for every cell to contain a tower. If the city has no initial tower, return -1.
Function
daysToCoverCity(city: int[][]) → intExamples
Example 1
city = [[1,0,0],[0,0,0]]return = 3The farthest cell is three orthogonal steps from the initial tower.
Example 2
city = [[1,0,1],[0,0,0],[0,1,0]]return = 1Every empty cell is adjacent to at least one of the three initial towers.
Example 3
city = [[1,1],[1,1]]return = 0The city is already fully covered.
Example 4
city = [[0,0],[0,0]]return = -1No initial tower exists, so expansion cannot begin.
Constraints
1 <= city.length <= 500.1 <= city[i].length <= 500.- Every row has the same length.
city[i][j]is0or1.
More Wells Fargo Online Assessment questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Shortest Atom Action PathOpenAI · OAOpenAI interview questions
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
- Count Islands with DFS and BFSVisa · OAVisa interview questions
- Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Count One Groups by SizeAgoda · OAAgoda interview questions
- Ascend Vertical Wall (For off-campus 2025 batch hiring :)Uber · OAUber interview questions
- Grid ExplorationIMC Trading · OAIMC Trading interview questions
- Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
- Nearest Different Maze Exit for a SnakeIntuit · OAIntuit interview questions