Isomorphic Strings Leetcode Solution

Problem Statement In this problem, we are given two strings, a and b. Our goal is to tell whether the two strings are isomorphic or not. Two strings are called isomorphic if and only if the characters in the first string can be replaced by any character(including itself) at all …

Read more

Island Perimeter Leetcode Solution

Problem Statement In this problem, we are given a grid in form of a 2-D array. grid[i][j] = 0 represents there is water at that point and grid[i][j] = 1 represents land. Grid cells are connected vertically/horizontally but not diagonally. There is exactly one island (a connected component of land …

Read more

Available Captures for Rook Leetcode Solution

Problem Statement In this problem, we are given a 2-D matrix that represents a chessboard with a white rook and some other pieces on it. White’s Rook is represented by the character ‘R’. White’s bishops are represented by ‘B’ and black’s pawns are represented as ‘p’. The problem guarantees that …

Read more

Decrypt String from Alphabet to Integer Mapping Leetcode Solution

Problem Statement In this problem, we are given a string containing digits (0-9) and ‘#’. We have to convert this string to a string of lowercase english letters by using the following mapping. Example s = “10#11#12” “jkab” Explanation: “10#” -> “j” , “11#” -> “k” , “1” -> “a” …

Read more

Word Search Leetcode Solution

Problem Statement Given an m x n board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where “adjacent” cells are horizontally or vertically neighbouring. The same letter cell may not be used more than once. Example …

Read more

Min Stack Leetcode Solution

Problem Statement Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Push element x onto stack. pop() — Removes the element on top of the stack. top() — Get the top element. getMin() — Retrieve the minimum element in the stack. …

Read more

Maximum Subarray Leetcode Solution

Problem Statement Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example nums = [-2,1,-3,4,-1,2,1,-5,4] 6 Explanation: [4,-1,2,1] has the largest sum = 6. nums = [-1] -1 Approach 1 (Divide and Conquer) In this approach …

Read more

Translate »