Sum Root to Leaf Numbers

Leetcode Solutions

Sum Root to Leaf Numbers Difficulty: Medium Topics: Tree, Depth-First Search, Binary Tree You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total […]

85. Maximal Rectangle Leetcode Solution

Leetcode Solutions

Maximal Rectangle Leetcode Solution Difficulty: Hard Topics: Array, Dynamic Programming, Stack, Matrix, Monotonic Stack Given a rows x cols binary matrix filled with 0‘s and 1‘s, find the largest rectangle containing only 1‘s and return its area. Example 1: Input: <code>matrix = [[“1″,”0″,”1″,”0″,”0”],[“1″,”0″,”1″,”1″,”1”],[“1″,”1″,”1″,”1″,”1”],[“1″,”0″,”0″,”1″,”0”]] Output: <code>6 Explanation: <code>The maximal rectangle is shown in the above picture. […]

79. Word Search Leetcode Solution

Leetcode Solutions

Word Search Leetcode Solution: Difficulty: Medium Topics: Array, String, Backtracking, Matrix Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell […]

78. Subsets : Leetcode Subsets Solution

Leetcode Solutions

Leetcode Subsets Solution Difficulty: Medium Topics: Array, Backtracking, Bit Manipulation Welcome to Leetcode Solution. Today we will solve Leetcode Subsets Solution. Let’s take a look at the problem first. Given an integer array nums of unique elements, return all possible subsets[^1] (the power set). The solution set must not contain duplicate subsets. Return the solution […]

75. Sort Colors Leetcode Solution

Leetcode Solutions

Sort Colors Solutions: Medium Topics: Array, Two Pointers, Sorting Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the […]

58. Length of Last Word

Leetcode Solutions

58. Length of Last Word Solution: Easy Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring[^1] consisting of non-space characters only. Example 1: Input: s = "Hello World" Output: 5 Explanation: The last word is "World" with length 5. […]

42. Trapping Rain Water

Leetcode Solutions

42. Trapping Rain Water Difficulty: Hard Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 […]

40. Combination Sum II

Leetcode Solutions

40. Combination Sum II Solution: Difficulty: Medium Topics: Array, Backtracking Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target. Each number in candidates may only be used once in the combination. Note: The solution set must not contain duplicate […]

17. Letter Combinations of a Phone Number

Leetcode Solutions

Letter Combinations of a Phone Number Solutions: Difficulty: Medium Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to […]

4. Median of Two Sorted Arrays

Leetcode Solutions

Median of Two Sorted Arrays Solutions: Difficulty: Hard Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).   Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and […]