Solve Grid and Counting Problems
GoogleSoftware Engineer · Technical ScreenLast updated
This question evaluates skills in grid-based graph traversal and connected-component detection for the island counting task, and combinatorial counting with multiset considerations for the target-word formation task.
A software engineering intern phone screen included two coding tasks:
- Count islands in a grid
Given an m x n grid of characters where '1' represents land and '0' represents water, return the number of islands. An island is formed by connecting adjacent land cells horizontally or vertically. You may assume all four edges of the grid are surrounded by water.
- Count ways to form a target word
Given an array of uppercase letters, count how many different ways you can choose letters from the array so that the chosen letters can be rearranged to spell GOOGLE. Each array element can be used at most once, and letters at different indices are considered different choices even if they contain the same character.
Design efficient algorithms for both tasks, and discuss the time and space complexity of your approach.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.