Applied Intuition interview questions & answers

10 real Applied Intuition interview questions with full model answers — Coding. Drawn from the same verified bank ChannelPulse drills from (10 Applied Intuition questions in total).

CodingMediumApplied IntuitionSoftware Engineer

1. Minesweeper (LeetCode)

Model answer

The task

Update a Minesweeper board after a cell is clicked. A clicked mine ends the game; an empty cell reveals either its adjacent mine count or, when there are none, the connected empty area and its bordering counts.

Key idea

Use breadth-first search to reveal empty cells. Count neighboring mines before revealing each cell, and only expand from cells with no adjacent mines.

Approach

  1. If the clicked cell contains a mine, change it to X and return.
  2. Otherwise, start a queue with the clicked cell.
  3. For each queued unrevealed cell, count mines in its eight neighbors.
  4. Reveal the cell as a digit if the count is positive; otherwise reveal it as B and enqueue its unrevealed neighbors.
  5. Return the updated board.
from collections import deque
from typing import List

class Solution:
    def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]:
        rows, cols = len(board), len(board[0])
        start_row, start_col = click

        if board[start_row][start_col] == "M":
            board[start_row][start_col] = "X"
            return board

        queue = deque([(start_row, start_col)])
        directions = [
            (-1, -1), (-1, 0), (-1, 1),
            (0, -1),           (0, 1),
            (1, -1),  (1, 0),  (1, 1),
        ]

        while queue:
            row, col = queue.popleft()

            # A cell may be queued by more than one neighboring blank.
            if board[row][col] != "E":
                continue

            neighbors = []
            mine_count = 0

            for dr, dc in directions:
                nr, nc = row + dr, col + dc
                if 0 <= nr < rows and 0 <= nc < cols:
                    neighbors.append((nr, nc))
                    if board[nr][nc] == "M":
                        mine_count += 1

            if mine_count:
                board[row][col] = str(mine_count)
            else:
                board[row][col] = "B"
                for nr, nc in neighbors:
                    if board[nr][nc] == "E":
                        queue.append((nr, nc))

        return board

Complexity:

  • Time: O(R × C), since each cell is revealed at most once.
  • Space: O(R × C) in the worst case for the BFS queue.

Common follow-ups

  • How would you avoid recursion depth issues? Use an iterative queue or stack, as above.
  • What if diagonal neighbors do not count? Check only the four orthogonal directions.
  • What if the board is too large for memory? Process it in regions or store only changed cells, depending on how the board is represented.
CodingMediumApplied IntuitionSoftware Engineer

2. Design Circular Queue (LeetCode)

Model answer

The task

Implement a fixed-capacity queue that wraps around its storage instead of shifting elements. It must support insertion, removal, checking whether it is empty or full, and reading the front and rear values.

Key idea

Store elements in a fixed-size array and track the front index and number of stored elements. Compute positions modulo the capacity so the queue reuses slots at the beginning of the array after reaching its end.

Approach

  1. Initialize an array of capacity k, a front index of 0, and a size of 0.
  2. On insertion, fail if full; otherwise write at (front + size) % capacity and increase the size.
  3. On removal, fail if empty; otherwise advance the front index modulo capacity and decrease the size.
  4. Read the front at the front index and the rear at (front + size - 1) % capacity.
  5. Return -1 for front or rear queries when the queue is empty.
class MyCircularQueue:
    def __init__(self, k: int):
        self.capacity = k
        self.values = [0] * k
        self.front_index = 0
        self.size = 0

    def enQueue(self, value: int) -> bool:
        if self.isFull():
            return False

        rear_index = (self.front_index + self.size) % self.capacity
        self.values[rear_index] = value
        self.size += 1
        return True

    def deQueue(self) -> bool:
        if self.isEmpty():
            return False

        self.front_index = (self.front_index + 1) % self.capacity
        self.size -= 1
        return True

    def Front(self) -> int:
        if self.isEmpty():
            return -1
        return self.values[self.front_index]

    def Rear(self) -> int:
        if self.isEmpty():
            return -1
        rear_index = (self.front_index + self.size - 1) % self.capacity
        return self.values[rear_index]

    def isEmpty(self) -> bool:
        return self.size == 0

    def isFull(self) -> bool:
        return self.size == self.capacity

Complexity:

  • Time: O(1) per operation; each operation updates or reads a constant number of values.
  • Space: O(k); the fixed-size array stores up to k elements.

Common follow-ups

  • How can the queue distinguish full from empty without a size field? Reserve one array slot, or track a separate full flag.
  • What changes for a dynamically growing queue? Allocate a larger array when full and copy elements in queue order.
  • How would you make it thread-safe? Protect operations with a lock, or use a suitable concurrent queue implementation.
CodingMediumApplied IntuitionSoftware Engineer

3. Game of Life (LeetCode)

Model answer

The task

Update a rectangular grid of live and dead cells by one generation, applying the standard Game of Life rules simultaneously. Modify the grid in place.

Key idea

Store each cell’s original state in its least significant bit and its next state in the next bit. This lets us calculate all new states while neighbors’ original states remain available.

Approach

  1. Return immediately if the grid has no rows or columns.
  2. For each cell, count live neighbors using only their original-state bits.
  3. Set the cell’s next-state bit when it survives or becomes live under the rules.
  4. After processing every cell, shift each value right once to keep only the new state.
from typing import List

class Solution:
    def gameOfLife(self, board: List[List[int]]) -> None:
        """Update board in place by one generation."""
        if not board or not board[0]:
            return

        rows, cols = len(board), len(board[0])
        directions = [
            (-1, -1), (-1, 0), (-1, 1),
            (0, -1),           (0, 1),
            (1, -1),  (1, 0),  (1, 1),
        ]

        for r in range(rows):
            for c in range(cols):
                live_neighbors = 0

                for dr, dc in directions:
                    nr, nc = r + dr, c + dc
                    if 0 <= nr < rows and 0 <= nc < cols:
                        live_neighbors += board[nr][nc] & 1

                is_live = board[r][c] & 1
                if live_neighbors == 3 or (is_live and live_neighbors == 2):
                    board[r][c] |= 2  # Record that the next state is live.

        for r in range(rows):
            for c in range(cols):
                board[r][c] >>= 1

Complexity:

  • Time: O(rows × cols), checking at most eight neighbors per cell.
  • Space: O(1), using the board itself to encode both states.

Common follow-ups

  • How would you support an infinite, mostly empty board? Store live-cell coordinates in a set and count neighbors of those cells.
  • How would you handle wraparound edges? Use modular indexing for neighbor coordinates.
  • How would you simulate many generations? Repeat the update, or detect repeated states to skip cycles.
CodingMediumApplied IntuitionSoftware Engineer

4. Shortest Path in Binary Matrix (LeetCode)

Model answer

The task

Find the minimum number of cells in a path from the top-left to the bottom-right of a binary grid. A move may go to any of the eight neighboring cells, and blocked cells cannot be used; return -1 if no path exists.

Key idea

Use breadth-first search (BFS), which visits cells in order of increasing path length. Mark cells when they are enqueued so each open cell is processed at most once.

Approach

  1. Return -1 if the grid is empty or either endpoint is blocked.
  2. Start BFS at the top-left with path length 1.
  3. For each cell, check all eight neighboring positions.
  4. Enqueue each in-bounds open neighbor and mark it visited immediately.
  5. Return the length when the bottom-right is reached; if BFS ends first, return -1.
from collections import deque
from typing import List

class Solution:
    def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int:
        n = len(grid)
        if n == 0 or grid[0][0] != 0 or grid[n - 1][n - 1] != 0:
            return -1

        directions = [
            (-1, -1), (-1, 0), (-1, 1),
            (0, -1),           (0, 1),
            (1, -1),  (1, 0),  (1, 1),
        ]

        # Store each cell together with the number of cells in its path.
        queue = deque([(0, 0, 1)])
        grid[0][0] = 1  # Mark visited; this modifies the input grid.

        while queue:
            row, col, distance = queue.popleft()

            if row == n - 1 and col == n - 1:
                return distance

            for dr, dc in directions:
                nr, nc = row + dr, col + dc
                if 0 <= nr < n and 0 <= nc < n and grid[nr][nc] == 0:
                    grid[nr][nc] = 1
                    queue.append((nr, nc, distance + 1))

        return -1

Complexity:

  • Time: O(n²), since each cell is enqueued at most once.
  • Space: O(n²) for the BFS queue in the worst case.

Common follow-ups

  • How would you avoid modifying the input? Keep a separate visited matrix.
  • What if moves are allowed only horizontally and vertically? Use four directions instead of eight.
  • What if each move has a different cost? Use Dijkstra’s algorithm rather than ordinary BFS.
CodingMediumApplied IntuitionSoftware Engineer

5. Find First and Last Position of Element in Sorted Array (LeetCode)

Model answer

The task

Given a sorted array and a target value, return the indices of its first and last occurrences. If the target is absent, return [-1, -1].

Key idea

Use binary search twice: once to find the first index whose value is at least the target, and once to find the first index whose value is greater than the target. The second boundary, minus one, is the target’s last index.

Approach

  1. Write a binary search that finds the first index meeting a chosen comparison.
  2. Find the first index with a value at least the target.
  3. If that index is past the array or does not contain the target, return [-1, -1].
  4. Find the first index with a value greater than the target.
  5. Return the first index and the second boundary minus one.
from typing import List

class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        def first_index(strictly_greater: bool) -> int:
            """Return the first index with value > target, or >= target."""
            left, right = 0, len(nums)

            while left < right:
                mid = (left + right) // 2
                qualifies = (
                    nums[mid] > target
                    if strictly_greater
                    else nums[mid] >= target
                )

                if qualifies:
                    right = mid
                else:
                    left = mid + 1

            return left

        first = first_index(strictly_greater=False)

        if first == len(nums) or nums[first] != target:
            return [-1, -1]

        after_last = first_index(strictly_greater=True)
        return [first, after_last - 1]

Complexity:

  • Time: O(log n), from two binary searches.
  • Space: O(1), excluding the returned list.

Common follow-ups

  • Can the search be done with one binary search? A single search finds only one occurrence; additional work is needed to locate both boundaries.
  • What if the array is empty? The first boundary is zero, so the method returns [-1, -1].
  • How would you count occurrences instead? Subtract the first index from the first index greater than the target.
CodingMediumApplied IntuitionSoftware Engineer

6. Merge Intervals (LeetCode)

Model answer

The task

Given a collection of intervals, combine every pair that overlaps and return the resulting non-overlapping intervals. The result should be ordered by starting point.

Key idea

Sort intervals by their start. Then scan once, keeping the most recently merged interval; each next interval either extends it or starts a new one.

Approach

  1. Sort the intervals by their start value.
  2. Initialize the result with the first interval, if any.
  3. For each remaining interval, compare its start with the end of the last result interval.
  4. If they overlap, update that end to the larger of the two ends.
  5. Otherwise, append the interval as a new result.
from typing import List

class Solution:
    def merge(self, intervals: List[List[int]]) -> List[List[int]]:
        if not intervals:
            return []

        intervals.sort(key=lambda interval: interval[0])
        merged = [intervals[0]]

        for start, end in intervals[1:]:
            # The intervals overlap, so extend the last merged interval.
            if start <= merged[-1][1]:
                merged[-1][1] = max(merged[-1][1], end)
            else:
                # No overlap: this interval begins a new merged range.
                merged.append([start, end])

        return merged

Complexity: Time: O(n log n), dominated by sorting n intervals.

Complexity: Space: O(n) for the merged result; sorting may also use up to O(n) space.

Common follow-ups

  • What if intervals that only touch at an endpoint should remain separate? Use start < merged[-1][1] as the overlap test.
  • How would you merge intervals as they arrive in sorted order? Skip sorting and apply the same scan, processing each interval once.
  • What if intervals are inserted one at a time into an already merged collection? Use binary search to find the insertion point, then merge neighboring overlaps.
CodingMediumApplied IntuitionSoftware Engineer

7. Find Duplicate File in System (LeetCode)

Model answer

The task

Given directory descriptions that pair file names with their contents, return groups of full file paths for files whose contents are identical. Omit files that have no duplicate.

Key idea

Use file contents as hash-map keys and collect the corresponding paths. After parsing all descriptions, keep only groups containing at least two paths.

Approach

  1. Create a map from content to a list of paths.
  2. For each description, separate its directory from its file entries.
  3. Parse each entry into a file name and content, then add the full path to the map.
  4. Return the path lists with at least two entries.
from collections import defaultdict
from typing import List

class Solution:
    def findDuplicate(self, paths: List[str]) -> List[List[str]]:
        paths_by_content = defaultdict(list)

        for description in paths:
            parts = description.split()
            directory = parts[0]

            for file_entry in parts[1:]:
                file_name, content_with_close = file_entry.split("(", 1)
                content = content_with_close[:-1]  # Remove the trailing ')'
                full_path = f"{directory}/{file_name}"
                paths_by_content[content].append(full_path)

        return [
            file_paths
            for file_paths in paths_by_content.values()
            if len(file_paths) > 1
        ]

Complexity:

  • Time: O(S), where S is the total number of characters parsed.
  • Space: O(S) for the content-to-path map and the returned groups.

Common follow-ups

  • What if contents are large? Hash the contents, then verify matches to handle hash collisions.
  • What if files change while scanning? Use a filesystem snapshot or track metadata and recheck before returning groups.
  • What if duplicate detection must be distributed? Partition by content hash, then group paths within each partition.
CodingHardApplied IntuitionSoftware Engineer

8. Number of Ships in a Rectangle (LeetCode)

Model answer

The task

Count the ships whose coordinates lie inside an inclusive rectangle. The only way to inspect the hidden ships is to ask an oracle whether a rectangle contains at least one.

Key idea

Use the oracle to discard empty regions, then split nonempty regions into smaller, disjoint rectangles. When a region contains just one coordinate, it can contain at most one ship, so count it directly.

Approach

  1. Return zero for an invalid rectangle.
  2. Ask the oracle whether the rectangle contains any ships; if not, stop exploring it.
  3. If the rectangle is a single coordinate, count one ship.
  4. Split each coordinate range at its midpoint, producing up to four non-overlapping subrectangles.
  5. Recursively count the ships in those subrectangles.
# The judge provides the Sea and Point types.
class Solution:
    def countShips(self, sea: 'Sea', topRight: 'Point',
                   bottomLeft: 'Point') -> int:
        def count(x1: int, y1: int, x2: int, y2: int) -> int:
            # Ignore empty regions created when a dimension has length one.
            if x1 > x2 or y1 > y2:
                return 0

            # Prune the entire region if the oracle says it is empty.
            if not sea.hasShips(Point(x2, y2), Point(x1, y1)):
                return 0

            # A single coordinate contains at most one ship.
            if x1 == x2 and y1 == y2:
                return 1

            mid_x = (x1 + x2) // 2
            mid_y = (y1 + y2) // 2

            # The ranges are inclusive and disjoint.
            return (
                count(x1, y1, mid_x, mid_y)
                + count(mid_x + 1, y1, x2, mid_y)
                + count(x1, mid_y + 1, mid_x, y2)
                + count(mid_x + 1, mid_y + 1, x2, y2)
            )

        return count(bottomLeft.x, bottomLeft.y, topRight.x, topRight.y)

Complexity:

  • Time: O(S log R) oracle calls in the worst case, where S is the number of ships and R is the larger side length; empty regions are pruned.
  • Space: O(log R) recursion depth.

Common follow-ups

  • What if the rectangle coordinates are very large? Split ranges recursively as above; work depends on occupied regions, not enumerating coordinates.
  • What if oracle calls are expensive? Cache answers for identical rectangles and avoid querying invalid regions.
  • Could you split only one dimension at a time? Yes; splitting the longer side can keep the recursion balanced while reducing unnecessary subdivisions.
CodingHardApplied IntuitionSoftware Engineer

9. Shortest Distance from All Buildings (LeetCode)

Model answer

The task

Given a grid of buildings, empty cells, and obstacles, find an empty cell with the smallest total walking distance to every building. Return -1 if no such cell exists.

Key idea

Run BFS from each building, moving only through empty cells. Accumulate each BFS distance and count how many buildings can reach each empty cell; only cells reached by all buildings are candidates.

Approach

  1. Record the coordinates of all buildings.
  2. Create matrices for cumulative distance and number of buildings reaching each cell.
  3. For each building, run BFS through empty cells, updating both matrices.
  4. Find the smallest cumulative distance among empty cells reached by every building.
  5. Return -1 if there is no valid candidate.
from collections import deque
from typing import List

class Solution:
    def shortestDistance(self, grid: List[List[int]]) -> int:
        if not grid or not grid[0]:
            return -1

        rows, cols = len(grid), len(grid[0])
        buildings = [
            (r, c)
            for r in range(rows)
            for c in range(cols)
            if grid[r][c] == 1
        ]

        # total[r][c] stores the sum of distances from buildings reached.
        total = [[0] * cols for _ in range(rows)]
        reached = [[0] * cols for _ in range(rows)]

        for start_r, start_c in buildings:
            queue = deque([(start_r, start_c, 0)])
            visited = [[False] * cols for _ in range(rows)]
            visited[start_r][start_c] = True

            while queue:
                r, c, distance = queue.popleft()

                for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nr, nc = r + dr, c + dc

                    if (
                        0 <= nr < rows
                        and 0 <= nc < cols
                        and grid[nr][nc] == 0
                        and not visited[nr][nc]
                    ):
                        visited[nr][nc] = True
                        next_distance = distance + 1
                        total[nr][nc] += next_distance
                        reached[nr][nc] += 1
                        queue.append((nr, nc, next_distance))

        if not buildings:
            return 0

        best = min(
            (
                total[r][c]
                for r in range(rows)
                for c in range(cols)
                if grid[r][c] == 0 and reached[r][c] == len(buildings)
            ),
            default=-1,
        )
        return best

Complexity:

  • Time: O(B × R × C), where each building’s BFS may visit the whole grid.
  • Space: O(R × C) for the matrices and BFS state.

Common follow-ups

  • Can the BFS work be reduced? Prune cells or regions that cannot possibly be reached by all buildings.
  • What if paths have different movement costs? Use Dijkstra’s algorithm from each building instead of BFS.
  • What if a path can pass through buildings? Change the traversal rule to allow building cells, while keeping candidate cells restricted to empty land.
CodingHardApplied IntuitionSoftware Engineer

10. Best Meeting Point (LeetCode)

Model answer

The task

Given a grid where some cells contain people, choose a grid location that minimizes the sum of Manhattan distances to all of them. Return that minimum total distance.

Key idea

Manhattan distance is the sum of independent row and column distances. For either coordinate, the sum of distances to a set of points is minimized by a median, so choose the median row and median column.

Approach

  1. Scan the grid and record the row and column of every occupied cell.
  2. Sort both coordinate lists.
  3. Use the middle value of each list as the meeting coordinates.
  4. Sum the Manhattan distance from each person to that location.
class Solution:
    def minTotalDistance(self, grid: list[list[int]]) -> int:
        rows = []
        cols = []

        # Record the coordinates of every person.
        for r, row in enumerate(grid):
            for c, cell in enumerate(row):
                if cell == 1:
                    rows.append(r)
                    cols.append(c)

        if not rows:
            return 0

        rows.sort()
        cols.sort()

        # A median minimizes the sum of absolute differences.
        meeting_row = rows[len(rows) // 2]
        meeting_col = cols[len(cols) // 2]

        return sum(
            abs(r - meeting_row) + abs(c - meeting_col)
            for r, c in zip(rows, cols)
        )

Complexity:

  • Time: O(mn + k log k), for scanning the grid and sorting k occupied coordinates.
  • Space: O(k), to store the occupied coordinates.

Common follow-ups

  • Can sorting be avoided? Use selection algorithms to find each median in expected O(k) time.
  • Can the coordinate lists be reduced? Yes; count occupied cells per row and column, then find weighted medians.
  • What if the distance metric changes? The median argument depends on Manhattan distance; other metrics may require a different optimization method.

Practice these out loud, don't memorise them

Reading an answer is not the same as being able to give one under pressure. ChannelPulse plays the interviewer, asks the follow-ups, and scores each answer with feedback and a model answer so you can hear the gap between what you said and what lands.

Get ChannelPulse Browse all questions