Question d’entretien chez Epic

4 leet code Q's. 2 easy 2 medium. Practice DFS and BFS in 2d array. Practice induction and properties of well ordered arrays.

Réponses aux questions d'entretien

Utilisateur anonyme

2 juin 2026

Here are 4 LeetCode-style practice questions tailored to your requested topics, broken down into two Easy and two Medium problems. --- ### 1. Flood Fill (Easy) * **Topic:** DFS/BFS in a 2D Array * **Problem Statement:** You are given an `m x n` integer grid `image` where `image[i][j]` represents the pixel value of the image. You are also given three integers `sr`, `sc`, and `color`. You should perform a flood fill on the image starting from the pixel `image[sr][sc]`. To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the *same* color, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of these connected pixels with `color`. Return the modified image. * **Example:** ```text Input: image = [,,], sr = 1, sc = 1, color = 2 Output: [,,] Explanation: From the center of the image (row 1, col 1), all pixels connected by the same color (1) are colored with 2. Note the bottom-right pixel is not changed because it is not 4-directionally connected to the starting pixel. ``` * **Algorithmic Hint:** You can use either a recursive DFS function or a queue-based BFS. Ensure you have a base condition to return early if the starting pixel already matches the target `color` to avoid infinite loops. --- ### 2. Check Monotonic Array (Easy) * **Topic:** Induction and Properties of Ordered Arrays * **Problem Statement:** An array is monotonic if it is either entirely non-increasing or entirely non-decreasing. * An array `nums` is non-decreasing if for all `i = nums[j]`. Given an integer array `nums`, return `true` if the given array is monotonic, or `false` otherwise. * **Example:** ```text Input: nums = Output: true Input: nums = Output: false ``` * **Algorithmic Hint:** This leverages simple mathematical induction. If a property holds true from index `i` to `i+1` for the entire array, it holds true globally. Scan the array in a single pass while tracking whether the trends break. --- ### 3. Number of Closed Islands (Medium) * **Topic:** DFS/BFS in a 2D Array * **Problem Statement:** Given a 2D `grid` consists of `0`s (land) and `1`s (water). An island is a maximal 4-directionally connected group of `0`s and a *closed island* is an island totally (all left, top, right, bottom) surrounded by `1`s. Return the number of closed islands in the grid. * **Example:** ```text Input: grid = [ , , , , ] Output: 2 Explanation: Islands that touch the boundary of the grid are not considered closed because they cannot be surrounded by water on the boundary edge. Only internal land clusters qualify. ``` * **Algorithmic Hint:** Run a DFS/BFS traversal from every land pixel touching the boundary of the grid and flip those connected components to water (`1`), since they cannot form closed islands. Afterward, count how many remaining isolated land components (`0`s) you can find using standard grid traversal. --- ### 4. Search in Rotated Sorted Array (Medium) * **Topic:** Induction and Properties of Well-Ordered Arrays * **Problem Statement:** There is an integer array `nums` sorted in ascending order with distinct values. Prior to being passed to your function, `nums` is possibly rotated at an unknown pivot index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums, nums, ..., nums[k-1]]` (0-indexed). For example, `might become`. Given the array `nums` *after* the possible rotation and an integer `target`, return the index of `target` if it is in `nums`, or `-1` if it is not in `nums`. You must write an algorithm with $O(\log n)$ runtime complexity. * **Example:** ```text Input: nums =, target = 0 Output: 4 ``` * **Algorithmic Hint:** This problem relies heavily on the inductive properties of well-ordered arrays. Even when a sorted array is rotated, dividing it in half will *always* leave at least one half perfectly sorted. Use Binary Search: at each step, determine which half is normally ordered, check if the target falls within that ordered range, and adjust your search boundaries accordingly.

Utilisateur anonyme

2 juin 2026

1.Flood Fill (Easy) Topic: DFS/BFS in a 2D Array Problem Statement: You are given an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. You should perform a flood fill on the image starting from the pixel image[sr][sc]. To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of these connected pixels with color. Return the modified image. example Input: image = [,,], sr = 1, sc = 1, color = 2 Output: [,,] Explanation: From the center of the image (row 1, col 1), all pixels connected by the same color (1) are colored with 2. Note the bottom-right pixel is not changed because it is not 4-directionally connected to the starting pixel. 2. Search in Rotated Sorted Array (Medium)Topic: Induction and Properties of Well-Ordered ArraysProblem Statement: There is an integer array nums sorted in ascending order with distinct values. Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums, nums, ..., nums[k-1]] (0-indexed). For example, might become.Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums. You must write an algorithm with $O(\log n)$ runtime complexity. Input: nums =, target = 0 Output: 4

Utilisateur anonyme

21 déc. 2022

Answered both easy questions. Last two only wrote comments and some pseudo code.

9