1277. Count Square Submatrices with All Ones

1277. Count Square Submatrices with All Ones Difficulty: Medium Related Topics: Array, Dynamic Programming Given a m * n matrix of ones and zeros, return how many square submatrices have all ones. Example 1: Input: matrix = [   [0,1,1,1],   [1,1,1,1],   [0,1,1,1] ] Output: 15 Explanation: There are 10 squares of side 1.ContinueContinue reading “1277. Count Square Submatrices with All Ones”

368. Largest Divisible Subset

368. Largest Divisible Subset Difficulty: Medium Related Topics: Math, Dynamic Programming Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0. If there are multiple solutions, return any subset is fine.ContinueContinue reading “368. Largest Divisible Subset”

1442. Count Triplets That Can Form Two Arrays of Equal XOR

1442. Count Triplets That Can Form Two Arrays of Equal XOR Difficulty: Medium Related Topics: Array, Math, Bit Manipulation Given an array of integers arr. We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). Let’s define a and b as follows: a = arr[i] ^ContinueContinue reading “1442. Count Triplets That Can Form Two Arrays of Equal XOR”

1222. Queens That Can Attack the King

1222. Queens That Can Attack the King Difficulty: Medium Related Topics: Array On an 8×8 chessboard, there can be multiple Black Queens and one White King. Given an array of integer coordinates queens that represents the positions of the Black Queens, and a pair of coordinates king that represent the position of the White King,ContinueContinue reading “1222. Queens That Can Attack the King”

1338. Reduce Array Size to The Half

1338. Reduce Array Size to The Half Difficulty: Medium Related Topics: Array, Greedy Given an array arr.  You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half of the integers of the array are removed.ContinueContinue reading “1338. Reduce Array Size to The Half”

357. Count Numbers with Unique Digits

357. Count Numbers with Unique Digits Difficulty: Medium Related Topics: Math, Dynamic Programming, Backtracking Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100,  ContinueContinue reading “357. Count Numbers with Unique Digits”

145. Binary Tree Postorder Traversal

145. Binary Tree Postorder Traversal Difficulty: Medium Related Topics: Stack, Tree Given the root of a binary tree, return the postorder traversal of its nodes’ values. Follow up: Recursive solution is trivial, could you do it iteratively? Example 1: Input: root = [1,null,2,3] Output: [3,2,1] Example 2: Input: root = [] Output: [] Example 3: Input:ContinueContinue reading “145. Binary Tree Postorder Traversal”

986. Interval List Intersections

986. Interval List Intersections Difficulty: Medium Related Topics: Two Pointers Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order. Return the intersection of these two interval lists. (Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <=ContinueContinue reading “986. Interval List Intersections”