Track your progress and attempt this list on GfG Practice. Elements in the Range. 01 Matrix Problem Description. Back to Explore Page. A move can be made to a cell grid [i] [j] only if grid [i] [j] = 0 and only left, right, up and down movements are permitted. Time complexity: O (M*N*P) where grid is of size M*N and P is the count of 1-cells. vscode","path":". Note: The Graph doesn't contain any negative weight cycle. Try all 8 possible positions where a Knight can reach from its position. The distance is calculated as |i1 – i2| + |j1 – j2|, where i1, j1 are the row number and column number of the current cell and i2, j2 are the row number and column number of the nearest cell having value 1. Definition: The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given an array of size N consisting of only 0's and 1's. You are given a weighted undirected graph having n vertices numbered from 1 to n and m edges describing there are edges between a to b with some weight, find the shortest path between the vertex 1 and the vertex n and if path does not. Given a grid of size M*N with each cell consisting of an integer which represents points. Distance Of Nearest Cell Having 1 In A Binary Matrix You have been given a binary matrix 'MAT' containing only 0’s and 1’s of size N x M. Distance of Nearest Cell having 1 Problem Statement: Given a binary grid of N*M. If source is already any of the corner then. The distance is. Example 1: Input: n = 6 A [] = {16,17,4,3,5,2} Output: 17 5 2 Explanation: The first leader is 17 as it is greater than all the elements to its right. push all the cells it can visit in the queue. Start from a 1-cell, and perform a Breadth First Search traversal, layer by layer. Given a matrix mat of size N x M where every element is either 'O' or 'X'. The graph is represented as an adjacency matrix of size n*n. . If the path is not possible. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. For each 0-cell, compute its distance from every 1-cell and store the minimum. Tutorials. Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that “works”. Source Code :. Step3: Initialize the start index with level = 0 and reduce the matrix. GfG Weekly + You = Perfect Sunday Evenings! Given an array with repeated elements, the task is to find the maximum distance between two occurrences of an element. We choose one of the 8 moves in this step). The parent of node T will always have a label. Given a grid of dimension nxm where each cell in the grid can have values 0, 1 or 2 which has the following meaning: 0 : Empty cell 1: Cells have fresh oranges 2: Cells have rotten oranges . Find the number of islands. Nearest 1 in a binary matrix; Distance of nearest cell having 1 in a binary matrix; Minimum distance to the corner of a grid from source; Minimum cost to reach from the top-left to the bottom-right corner of a matrix; Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell Distance of nearest cell having 1 in a binary matrix; Minimum cost to reach from the top-left to the bottom-right corner of a matrix; Convert given lower triangular Matrix to 1D array; Minimum number of jumps to obtain an element of opposite parity; Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell Constraints: 1 ≤ n, m ≤ 500. Given a binary grid of n*m. Implementation of Efficient Approach: C++ // C++ program to demonstrate // multi-source BFS. Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. You start at 0 and can go either to the left or to the right. IF the element on left of previous leftmost 1 is 0, ignore this row. weight of 3rd cell = 0. Select D’ ⊆ D, the set of k nearest training data points to the query points; Predict the class of the query point, using distance-weighted voting. Feeling lost in the world of random DSA topics, wasting time without progress?. Here, vector1 is the first vector. An Efficient Solution is based on. {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"2D Hopscotch. The questions will be featured from a pool of public problems from the GFG Practice Portal. the only used space is dp vector of o(n). We can calculate Minkowski distance between a pair of vectors by apply the formula, ( Σ|vector1i – vector2i|p )1/p. The formula for distance between two point (x1, y1) and (x2, y2) is. You are given an n x m binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. Therefore, the following relation gives the sum of distances of all nodes from a node,. However, Voronoi diagrams could be designed using other distance functions. Similarly, the next leader is 5. grid [i] [j] == 0 or grid [i] [j] == 1. Solve one problem based on Data Structures and Algorithms every day and win exciting prizes. A loop here means that the last node of the link list is connected to the node at position X (1-based index). For each tower, you must perform exactly one of the following operations exactly once. {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"2D Hopscotch. The Nth Fibonacci Number can be found using the recurrence relation shown above: if n = 0, then return 0. Also, since there is no element next to the last element, replace it with -1. Nearest 1 in a binary matrix; Distance of nearest cell having 1 in a binary matrix; Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell; Word Ladder - Set 2 ( Bi-directional BFS ) Minimum distance to the corner of a grid from sourceWe can change all its values to 100 with minimum cost, |1 - 100| + |100 - 100| + |101 - 100| = 100. The idea is to traverse the matrix for each cell and find the minimum distance, To find the minimum distance traverse the matrix and find the cell which. Note: If the difference is same for two values print the value which is greater than the given number. You have to do at most one “Flip” operation of any subarray. Expected Time Complexity: O (m* log (n)) Expected Space Complexity: O (n) Constraint: 2 <= n <= 105. Figure 8: Comparison of Voronoi diagrams using the Euclidean (left) and Manhattan (right) distance for a same set of points Source: Wikipedia. Constraints :K-NN is less sensitive to outliers compared to other algorithms. There should be atleast one 1 in the grid. A cell in the given maze has a value of -1 if it is a blockage or dead-end, else 0. Time. Below is the implementation of the above. Solve company interview questions and improve your coding intellect Construct a Matrix such that each cell consists of sum of adjacent elements of respective cells in given Matrix. The rightmost element is always a leader. vscode","path":". Store all horizontal and vertical positions of all group member. If the reachable position is not already visited and is inside the board, push this state into the queue with a distance 1 more than its parent state. Find the distance of the nearest 1 in the grid for each cell. Since all the sources have a distance = 0, in the beginning, the adjacent non-source vertices will get a distance = 1. . INPUT FORMAT: The first line contains the number of cells N. . 1. Problem – 01 Matrix. Feeling lost in the world of random DSA topics, wasting time without progress? It's time. Link: Link: Sum of minimum and maximum elements of. The insert and delete operations on Balanced BST also take O(log k) time. Time Complexity: O(m x n) Auxiliary Space: O( m *n)+O(m+n) , (m*n) extra array space and (m+n) recursive stack space. Element with left side smaller and right side greater. The distance is calculated as|i1- i2| + |j1- j2|, where i, jare the row number and column number of the current cell,. Note: You can only move left, right, up and down, and only through cells that contain 1. Distance =. Note: An island is either surrounded by water or boundary of grid and is formed by connecting adjacent lands horizontally or vertically or diagonally i. Time complexity: O (M*N*P) where grid is of size M*N and P is the count of 1-cells. Find the minimum number of steps required to reach from (0,0) to (X, Y). That is, for every x, y, z ∈ A N: 0 ≤ d (x, y) ≤ N. Step1: Get the index of first (or leftmost) 1 in the first row. Your task is to complete the function getXor to return the XOR of the given range a and b. cpp","path":"Graph/Geeksforgeeks/Alex. If a vertices can't be reach from the S then mark the distance as 10^8. The nearest perfect square of arr [2] (= 7) is 9. Link: Link: Sum of minimum and maximum elements of. Distance of nearest cell having 1 in a binary matrix; Check if a cycle of length 3 exists or not in a graph that satisfy a given condition; Maximum height of an elevation possible such that adjacent matrix cells have a difference of at most height 1; Minimum distance to the corner of a grid from source; Edge Coloring of a GraphGiven a binary grid of n*m. Contests. If the x and y become the boundary edges any time return val. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. Minimize the Heights II. 0:57 Example Explanation. Time Complexity: O(K) + O(m * log(k)) , where M = N – K Auxiliary Space: O(K) Note: We can also use a Balanced Binary Search Tree instead of a Heap to store k+1 elements. cpp. Step1: Create a class (Node) that can store the reduced matrix, cost, current city number, level (number of cities visited so far), and path visited till now. * represents cell you can travel. Find the shortest distance from a source cell to a destination cell, traversing through limited cells only. e, zero points. cpp. 77, which is minimum obtainable total distance. Check if,. The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix (containing only 0s and 1s) with at least one 1. Let us discuss Rat in a Maze as another example problem that can be solved using Backtracking. It has to reach the destination at (N – 1, N – 1). Back to Explore Page. Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. 3 elements arranged at positions 1, 7 and 12, resulting in a minimum distance of 5 (between 7 and 12) A Naive Solution is to consider all subsets of size 3 and find the minimum distance for every subset. So during the first step of KNN, we must load the training as well as test data. This is the best place to expand your knowledge and get prepared for your next interview. If the xor of all the elements of row i and column j is equal then increase the count one. Does robot moves circular. Find the distance of the nearest 1 in the grid for each cell. e. Let us first verify that the conditions of DP are still satisfied. cpp Go to file Go to file T; Go to line L; Copy path Copy permalink; This commit does not belong to any branch on this repository, and may belong to a. cpp","contentType":"file"},{"name":"3 Divisors. Let the minimum be d. Amazon SDE Sheet. After including 0 to sptSet, update distance values of its adjacent vertices. {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":". So the idea is to do a breadth-first search from the starting cell till the ending cell is. e 2) So, cell 2 is the output. Path to reach border cells from a given cell in a 2D Grid without crossing specially marked cells. cpp","path":"2D Hopscotch. 9:19 C++ Code Explanation. Equal point in a string of brackets. The distance is calculated as |i1 - i2| + |j1 - j2|, where i1, j1 are the row number and column number of the current cell, and i2, j2 are the row number and column number of the nearest cell having value 1. Given an infinite number line. Paytm. If the pat. vscode","contentType":"directory"},{"name":"DP","path":"DP","contentType. For target node 8 and k is 2, the node 22 comes in this category. Distance of nearest cell having 1. If it contains 2 : means we can go Down from that cell only. 2. Manhattan Distance between two points (x 1, y 1) and (x 2, y 2) is: |x1 – x2| + |y1 – y2|. cpp. The distance is calculated as |i1 - i2| + |j1 - j2|, where i1, j1 are the row number and column number of the current cell, and i2, j2&. You can travel back in time within the same calendar year. The only problem is I am able to do it with two dfs but I was told to do it in O (logn). If all squares are visited print the solution Else a) Add one of the next moves to solution vector and recursively check if this move leads to a solution. cpp","path":"2D Hopscotch. Do all the possible moves (right, left, up and down) possible. The distance is calculated as |i1 - i2| + |j1 - j2|, where i1, j1 are the row number and column number of the current cell, and i2, j2 are the row number and column number of the nearest cell having value 1. A Computer Science portal for geeks. Given a binary grid of n*m. GfG-Problem Link:. vscode","contentType":"directory"},{"name":"DP","path":"DP","contentType. Example 1. The distance is calculated as |i 1 - i 2 | + |j 1 - j 2 |, where i 1, j 1 are the row number and column number of the current cell, and i 2, j 2 are the row number and column number of the nearest cell having value 1. Time Complexity: O(n) Auxiliary Space: O(1) Method 2 (Binary Search) First check whether middle element is Fixed Point or not. Given a matrix of dimension m * n where each cell in the matrix can have values 0, 1, or 2 which has the following meaning: . 0: Empty cell; 1: Cells have fresh oranges; 2: Cells have rotten oranges; The task is to the minimum time required so that all the oranges become rotten. Example 1: Input: N =. That is to say, if you. Given an array of N integers arr [] where each element represents the maximum length of the jump that can be made forward from that element. 1 Time Machine costs 60 GeekBits. This is the best place to expand your knowledge and get prepared for your next interview. Run a while loop till l <= r, lowerbound is less than the upperbound. Replace all 'O' or a group of 'O' with 'X' that are surrounded by 'X'. Recommended Practice. Note: An island is either surrounded by water or boNaive Approach: The simplest idea to solve this problem is that, whenever a node is traversed on the left or right of a node, then the distances of the nodes their subtrees reduces by 1, and distance of the rest of the nodes from that node increases by 1. Select a problem from the Calendar to use Time Machine. gitattributes","path":". If there are no negative weight cycles, then we can solve in O (E + VLogV) time using. Let’s address those issues in more detail now. 0 <= m <= 105. GFG Weekly Coding. This is the best place to expand your knowledge and get prepared for your next interview. You don't need to read input or print anything. Space Complexity: O(1), no extra space is required. Amazon Interview Experience | Set 414 (For SDET-1) Walmart Lab Interview Experience | Set 8 (Off-Campus 3 Years Experience) Minimum cost to reach from the top-left to the bottom-right corner of a matrix; Distance of nearest cell having 1 in a binary matrix; Maximum cost path from source node to destination node via at most K. Editorial. Input: The first line of input is an integer T denoting the. Every cell of the maze contains these numbers 1, 2 or 3. Return the count. Apply to 6 Companies through 1 Contest! Given array A [] of integers, the task is to complete the function findMaxDiff which finds the maximum absolute difference between nearest left and right smaller element of every element in array. For clarity, you may assume that the tree satisfies the following conditions. For example in above diagram, horizontal positions are {0, 2, 0} and vertical positions are {0, 2, 4}. Iterate over array from left to right. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation: with seed values and and . Example 2: Input: N = 1500 Output: 1521 21 Explanation: Two of the. Distance array will be to store the distance to nearest island. Compute d(x i, x) for i = 1, . Given a n * m matrix grid where each element can either be 0 or 1. In the second iteration we have (1, 2) and so on where (1) and (2) are. vscode","path":". Finally, return the largest of all minimum distances. Find the distance of the nearest 1 in the grid for each cell. minHeight =. {"payload":{"allShortcutsEnabled":false,"fileTree":{"Stack-Queue":{"items":[{"name":"Circular_tour. Given an array of sorted integers. Naive Approach: The idea is to create another array that is double the size of the original array, such that the elements of this new array (copy array) are just the. {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"1971. Formally, select a range (l, r) in the array A [], such that (0 ≤ l ≤ r < n) holds and flip the elements in this range to get the maximum ones in the final array. cpp. We have to avoid landmines and their four adjacent cells (left, right, above and below) as they are also unsafe. Mark the source cell as visited and initialize its distance to 0. BiWizard School Contest. The minimum cost to reach N-1 from 0 can be recursively written as following: minCost (0, N-1) = MIN { cost [0] [n-1], cost [0] [1] + minCost (1, N-1), minCost (0, 2. A Computer Science portal for geeks. Distance = 2 – 1 = 1. cpp. Distance = 5 – 3 = 2. This auxiliary stack will keep track of the maximum element. Replace every element with the next greatest element (greatest element on its right side) in the array. If n - a > b - n then the answer is b otherwise the answer is a. Determine whether or not there exist two elements in Arr whose sum is exactly X. Given a grid with each cell consisting of positive, negative or no points i. Platform to practice programming problems. Equal Sum. e. You need to find the the length of the largest cycle in the maze. Exclusively for Freshers! Participate for Free on 21st November & Fast-Track Your Resume to Top Tech Companies. Examples: Input: N = 15, M = 12, R = 1, C = 6. ; Iterate over the array and keep calculating currPrefixSum. Use a table to store solutions of subproblems to avoiding recalculate the same subproblems multiple times. Edge [i] is -1 if the i th cell doesn’t have an exit. Initialize a priority queue to store the cells to be processed, and add the source cell to the priority queue. Example 1: Distance of nearest cell having 1 | Practice | GeeksforGeeks. Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, etc. 2) The sum j is achieved excluding i'th item. Find the shortest path from srNearest multiple of 10. Always check online for programming topics frequently asked in MathWorks interviews and practice them accordingly (Linked. Examples: Input: a[] = {1, 5, 11, 20}, b[] = {4, 8, 15} Output: 5 Explanation: The minimum range. The distance is calculated as |i 1 - i 2 | + |j 1 - j 2 |, where i 1, j 1 are the row number and column number of the current cell, and i 2, j 2 are the row number and column number of the nearest cell having value 1. By using this concept, the distance between two strings is the sum of distances of corresponding letters. If no valid path exists then print -1. Method 1:Method 1:Using a custom function. Ln 1, Col 1. Distance = 6 – 2 = 4. ELSE Move left until a 0 is found. Jobs. C++ Program for Shortest distance between two cells in a matrix or grid. 1) push () which adds an element to the top of stack. Find if Path Exists in Graph","contentType. In that case you must submit your solution again to maintain the streak and earn a Geek Bit. The root of the tree is labeled 1. Count cells in a grid from which maximum number of cells can be reached by K vertical or horizontal jumps. Priority queue of pairs in C++ (Ordered by first) Count all elements in the array which appears at least K times after their first occurrence. Steps involved in detecting cycle in a directed graph using BFS. Auxiliary Space: O(1) A better solution is to sort the arrays. Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on scheduleMax distance between same elements. We need to find minimum initial points to reach cell (m-1, n-1) from (0, 0). 3. Given an array Arr of N positive integers and another number X. Explanation: weight of 0th cell is 0. DSA REPOSITORY: + DSA COURSE: playlist: POTD link ::: you like this content please hit like and subscribe. You have got a maze, which is a n*n Grid. If x is not present in the array (arr) then return 0. cpp","contentType":"file"},{"name":"3 Divisors. Find the minimum numb. Determine whether or not there exist two elements in Arr whose sum is exactly X. While the priority queue is not empty, pop the cell with the minimum distance from the priority queue. Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell; Distance of nearest cell having 1 in a binary matrix; Minimum distance to the corner of a grid from source; Minimum cost to reach from the top-left to the bottom-right corner of a matrix; Implementing Water Supply Problem using Breadth First. 2) pop () which removes an element from top of stack. First, right shift N, K+1 times followed by left shifting the result K times, which gives the count of numbers satisfying the given condition till the nearest power of 2 less than N. calculate distance between two points. Explanation: Largest minimum distance = 5. Maximum of all distances to the nearest 1 cell from any 0 cell in a Binary matrix. In each recursive call get all the. {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"0239-sliding-window-maximum","path":"0239-sliding-window-maximum","contentType":"directory. Example 1: Input: N=6 knightPos [ ] = {4, 5} targetPos [ ] = {1, 1} Output: 3 Explanation: Knight takes 3 step to reach from (4, 5) to (1, 1): (4, 5) -> (5, 3. Find all possible paths that the rat can take to reach from. We can get above formula by simply applying Pythagoras theorem. Time Complexity: O(n^2). Key Pair. Dequeue the front node. b) Then throw 6 to reach 28. Find the distance of the nearest 1 in the grid for each cell. Can you solve this real interview question? Minimum Operations to Remove Adjacent Ones in Matrix - Level up your coding skills and quickly land a job. java","contentType":"file. The path can only be created out of a cell if its value is 1. Iterate till the queue is empty or we reach any boundary edge. So if a person is standing at i-th stair, the person can move to i+1, i+2, i+3-th stair. Consider a directed graph whose vertices are numbered from 1 to n. So sptSet becomes {0}. Find the distance of the nearest 1 in the grid for each cell. So Balanced BST-based method will also take O(n log k) time, but the Heap based method. Below is the implementation of the. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. edge [i] is . Then minimum steps will be 4. The distance transform [2] is closely related to a Voronoi diagram (see Figure 5). You are given the tree in the form of an array A[1. Two cells are. Input : arr [] = [4, 6] Output : 2. Find whether there is path between two cells in matrix using Breadth First Search: The idea is to use Breadth-First Search. Sample Output 1 : 5 2 Explanation of Sample Input 1 : For the first test case, the shortest path between the source cell (0, 0) and destination cell (2,3) is highlighted in the figure below, having a length of 5. At i = 1. Example 1: Input: N = 25 Output: 25 0 Explanation: Since 25 is a perfect square, it is the closest perfect square to itself and absolute difference is 25-25=0. Does robot moves circular. . 1. Then sort the array according to the Euclidean distance found and print the first k closest points from the list. e. You are given a weighted undirected graph having n vertices numbered from 1 to n and m edges describing there are edges between a to b with some weight, find the shortest path between the vertex 1 and the vertex n and if path does not exist then return a list consisting of only -1. 3. Compare each element with the given element x. Count of cells in a matrix which give a Fibonacci number when the. Replace all 'O' or a group of 'O' with 'X' that are surrounded by 'X'. Approach: Follow the steps below to solve the problem: Traverse the array from left to right. . Check if n2 or any of its. for example: dist (c, e) = dist (e, c) = 2. Given the integers N, M, R and C where N and M denotes the number of rows and columns in a matrix and (R, C) denotes a cell in that matrix, the task is to find the distance of the farthest cell from the cell (R, C). This approach allows the algorithm. Given a grid of size n*m (n is the number of rows and m is the number of columns in the grid) consisting of '0's (Water) and '1's(Land). Let sum of all the elements be S. Input n= 6 arr = {1, 1, 2, 2, 2, 1} Output 5 Explanation arr [] = {1, 1, 2, 2, 2, 1} Max Distance: 5 Distance for 1 is: 5-0 = 5 Distance for 2 is. . 4) Take the minimum of two smallest distances. 2:38 Logic Explanation. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. 1) We sort all points according to x coordinates. The idea is to simply use Kahn’s algorithm for Topological Sorting. Find the distance of the nearest 1 in the grid for each cell. Visited array: an array initialized to 0 indicating unvisited nodes. Distance of nearest cell having 1 in a binary matrix; Minimum cost to reach from the top-left to the bottom-right corner of a matrix; Implementing Water Supply Problem using Breadth First Search; Shortest path between two points in a Matrix with at most K obstacles; Minimum distance to fetch water from well in a villageStep 1: The set sptSet is initially empty and distances assigned to vertices are {0, INF, INF, INF, INF, INF, INF, INF} where INF indicates infinite. Consider each cell as a node and each boundary between any two adjacent cells be an edge. ,n , the distance between the query point and every other point in the training set. Mark the source cell as visited and initialize its distance to 0. If the end of array is reached and the element is not found, return -1Rearrange an array such that every odd indexed element is greater than it previous. The distance is calculated as |i 1 - i 2 | + |j 1 - j 2 |, where i 1, j 1 are the row number and column number of the current cell, and i 2, j 2 are the row number and column number of the nearest cell having value 1. The second line has a list of N values of the edge [ ] array, where edge [i] conatins the cell. We define ‘ g ’ and ‘ h ’ as simply as possible below. e. cpp. The task is to find the minimum number of steps required to go from the source (0, 0) to the destination (ROW-1, COL-1) with less than or. Solve company interview questions and improve your coding intellectFind the distance of the nearest 1 in the grid for each cell. Input: The first line of input is an integer T denoting the. -----. Practice. Additional constraint is that each cell can have at most one outgoing edge. Distance between two letters is the difference between their positions in the alphabet. cpp. If y is its child, then it is observed that the sum of distances of y and x are related as;. If source is already any of the corner then. The distance between two adjacent cells is 1. Practice. The new groups that can be formed by considering a member of every group are (1, 4), (2, 4), (3, 4). Now, check if the Kth bit is set in N or not. Example 1: Input: N = 13 , M = 4 Output: 12 Explana. The car has an infinite petrol capacity and starts with M amount of fuel. (n). Note: An island is either surrounded by water or boNaive Approach: The simplest idea to solve this problem is that, whenever a node is traversed on the left or right of a node, then the distances of the nodes their subtrees reduces by 1, and distance of the rest of the nodes from that node increases by 1. 2) Other nodes, may be an ancestor of target, or a node in some other subtree. Find an empty seat with maximum distance from an occupied seat. Facebook (Meta) SDE Sheet. We can move across a cell only if we have positive points. Explanation: 3 is at index 7 and 2 is at index 6, so the distance is 1. Rearrange a string so that all same characters become d distance away; Minimize the maximum difference between the heights. s represents ‘source’. Example 1: Given a matrix mat of size N x M where every element is either 'O' or 'X'. DSA REPOSITORY: + DSA COURSE:. Maximum of all distances to the nearest 1 cell from any 0 cell in a Binary matrix.