Computer Science

Number of Submatrices That Sum to Target

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 1074: Number of Submatrices That Sum to Target Read More »

Leetcode 895: Maximum Frequency Stack

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 895: Maximum Frequency Stack Read More »