835. Image Overlap

835. Image Overlap You are given two images img1 and img2 both of size n x n, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.) We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions that have a 1 in both images....

<span title='2021-06-07 00:00:00 +0000 UTC'>June 7, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

131. Palindrome Partitioning

131. Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. A palindrome string is a string that reads the same backward as forward. 1 2 3 4 5 6 7 8 9 Example 1: Input: s = "aab" Output: [["a","a","b"],["aa","b"]] Example 2: Input: s = "a" Output: [["a"]] Constraints: 1 <= s.length <= 16 s contains only lowercase English letters....

<span title='2021-06-06 00:00:00 +0000 UTC'>June 6, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

833. Find And Replace in String

833. Find And Replace in String To some string s, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size). Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y....

<span title='2021-06-06 00:00:00 +0000 UTC'>June 6, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

77. Combinations

77. Combinations Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Example 1: Input: n = 4, k = 2 Output: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] Example 2: Input: n = 1, k = 1 Output: [[1]] Constraints:...

<span title='2021-06-04 00:00:00 +0000 UTC'>June 4, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

1041. Robot Bounded In Circle

1041. Robot Bounded In Circle On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions: “G”: go straight 1 unit; “L”: turn 90 degrees to the left; “R”: turn 90 degrees to the right. The robot performs the instructions given in order, and repeats them forever. Return true if and only if there exists a circle in the plane such that the robot never leaves the circle....

<span title='2021-06-03 00:00:00 +0000 UTC'>June 3, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

17. Letter Combinations of a Phone Number

17. Letter Combinations of a Phone Number 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 any letters. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] Example 2: Input: digits = "" Output: [] Example 3: Input: digits = "2" Output: ["a","b","c"] Constraints:...

<span title='2021-06-03 00:00:00 +0000 UTC'>June 3, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

189. Rotate Array

189. Rotate Array Given an array, rotate the array to the right by k steps, where k is non-negative. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nums = [-1,-100,3,99], k = 2 Output: [3,99,-1,-100] Explanation: rotate 1 steps to the right: [99,-1,-100,3] rotate 2 steps to the right: [3,99,-1,-100] Constraints:...

<span title='2021-06-03 00:00:00 +0000 UTC'>June 3, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

22. Generate Parentheses

22. Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 1 2 3 4 5 6 7 8 9 Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output: ["()"] Constraints: 1 <= n <= 8 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Solution { public List<String> generateParenthesis(int n) { List<String> res = new ArrayList<>(); backtracking("(", 1, 0, n, res); return res; } void backtracking(String s, int open, int closed, int n, List<String> res) { if (open + closed == 2 * n) { res....

<span title='2021-06-03 00:00:00 +0000 UTC'>June 3, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

90. Subsets II

90. Subsets II Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. 1 2 3 4 5 6 7 8 9 Example 1: Input: nums = [1,2,2] Output: [[],[1],[1,2],[1,2,2],[2],[2,2]] Example 2: Input: nums = [0] Output: [[],[0]] Constraints: 1 <= nums.length <= 10 -10 <= nums[i] <= 10 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class Solution { public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> res = new ArrayList<>(); List<Integer> current = new ArrayList<>(); Arrays....

<span title='2021-06-03 00:00:00 +0000 UTC'>June 3, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

343. Integer Break

343. Integer Break Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers. Return the maximum product you can get. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: n = 2 Output: 1 Explanation: 2 = 1 + 1, 1 × 1 = 1. Example 2: Input: n = 10 Output: 36 Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36....

<span title='2021-05-30 00:00:00 +0000 UTC'>May 30, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

46. Permutations

46. Permutations Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Example 3: Input: nums = [1] Output: [[1]] Constraints: 1 <= nums.length <= 6 -10 <= nums[i] <= 10 All the integers of nums are unique....

<span title='2021-05-30 00:00:00 +0000 UTC'>May 30, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

78. Subsets

78. Subsets Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. 1 2 3 4 5 6 7 8 9 Example 1: Input: nums = [1,2,3] Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] Example 2: Input: nums = [0] Output: [[],[0]] Constraints: 1 <= nums.length <= 10 -10 <= nums[i] <= 10 All the numbers of nums are unique....

<span title='2021-05-30 00:00:00 +0000 UTC'>May 30, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1877. Minimize Maximum Pair Sum in Array

1877. Minimize Maximum Pair Sum in Array The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8. Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:...

<span title='2021-05-29 00:00:00 +0000 UTC'>May 29, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

221. Maximal Square

221. Maximal Square Given an m x n binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. 1 2 3 4 Example 1: Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] Output: 4 1 2 3 4 Example 2: Input: matrix = [["0","1"],["1","0"]] Output: 1 1 2 3 4 Example 3: Input: matrix = [["0"]] Output: 0 Constraints: m == matrix.length n == matrix[i].length 1 <= m, n <= 300 matrix[i][j] is ‘0’ or ‘1’....

<span title='2021-05-28 00:00:00 +0000 UTC'>May 28, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1852. Distinct Numbers in Each Subarray

1852. Distinct Numbers in Each Subarray Given an integer array nums and an integer k, you are asked to construct the array ans of size n-k+1 where ans[i] is the number of distinct numbers in the subarray nums[i:i+k-1] = [nums[i], nums[i+1], …, nums[i+k-1]]. Return the array ans. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example 1: Input: nums = [1,2,3,2,2,1,3], k = 3 Output: [3,2,2,2,3] Explanation: The number of distinct elements in each subarray goes as follows: - nums[0:2] = [1,2,3] so ans[0] = 3 - nums[1:3] = [2,3,2] so ans[1] = 2 - nums[2:4] = [3,2,2] so ans[2] = 2 - nums[3:5] = [2,2,1] so ans[3] = 2 - nums[4:6] = [2,1,3] so ans[4] = 3 Example 2: Input: nums = [1,1,1,1,2,3,4], k = 4 Output: [1,2,3,4] Explanation: The number of distinct elements in each subarray goes as follows: - nums[0:3] = [1,1,1,1] so ans[0] = 1 - nums[1:4] = [1,1,1,2] so ans[1] = 2 - nums[2:5] = [1,1,2,3] so ans[2] = 3 - nums[3:6] = [1,2,3,4] so ans[3] = 4 Constraints:...

<span title='2021-05-27 00:00:00 +0000 UTC'>May 27, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx