# Leetcode Detailed Solutions

## Leetcode 1074: Number of Submatrices That Sum to Target

CATEGORY: HARD Problem Given a matrix and a target, return the number of non-empty submatrices that sum to target. A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2. Two submatrices (x1, y1, x2, y2) and (x1′, y1′, x2′, y2′) are different if they have some different coordinate: for example, if x1 != x1′. Examples First […]

## Leetcode 895: Maximum Frequency Stack

CATEGORY: HARD Problem Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. Implement the FreqStack class: Examples First Example : Constraints: Solution Approach Solution Logic In this problem of Maximum Frequency Stack, the main task is to find the frequency of the value in the stack.

## Leetcode 31: Next Permutation

CATEGORY: MEDIUM Problem A permutation of an array of integers is an arrangement of its members into a sequence or linear order. The next permutation of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then

## Leetcode 895: Maximum Frequency Stack

CATEGORY: HARD Problem Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. Implement the FreqStack class: Examples Example 1: Constraints: Solution Approach In this problem of Maximum Frequency Stack, the main task is to find the frequency of the value in the stack. So, to find

## Leetcode 6: Zigzag Conversion

CATEGORY: MEDIUM Problem The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

And then read line by line: “PAYPALISHIRING” Write the code that will take a string and make this conversion given a number

## Leetcode 62: Unique Paths

Category: Medium Problem A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below). How many

## Leetcode 409: Longest Palindrome | Leetcode Easy

Category: Easy Problem Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, “Aa” is not considered a palindrome here. Problem Link. Examples Example 1: Example 2: Constraints 1 <= s.length <= 2000 s consists of lowercase and/or uppercase English letters only. Solution Approach In this

## Leetcode 1672: Richest Customer Wealth

Category: Easy Problem You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ customer has in the j​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has. A customer’s wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth. Problem Link. Examples Example 1: Example 2: Constraints

## Leetcode 136: Single Number

Category: Easy Problem Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. Follow up: Could you implement a solution with a linear runtime complexity and without using extra memory? Problem Link. Examples Example 1: Example 2: Constraints 1 <= nums.length <= 3 * 104 -3 * 104 <= nums[i] <= 3 * 104

## Leetcode 27: Remove Element

Category: Easy Problem Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn’t matter what you leave beyond the new length. https://leetcode.com/problems/remove-element Examples Example