Combination Sum 4 - All permutations

Problem Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target. The test cases are generated so that the answer can fit in a 32-bit integer. Examples Example 1: Input: nums = [1,2,3], target = 4 Output: 7 Explanation: The possible combination ways are: (1, 1, 1, 1) (1, 1, 2) (1, 2, 1) (1, 3) (2, 1, 1) (2, 2) (3, 1) Note that different sequences are counted as different combinations. ...

Generate Parentheses Problem

Problem Implement an algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses. OR Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Follow up Make sure the returned list of strings are sorted. Examples Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] ...

Print All Combinations of subset of size K from Given Array

Problem Given an array of integers of size n, print or return all the subsets of size k. (k<=n) Examples Example 1: Input: nums = [1, 2, 3, 4, 5], k = 3 Output: [ [1 2 3], [1 2 4], [1 2 5] [1 3 4], [1 3 5], [1 4 5], [2 3 4], [2 3 5], [2 4 5], [3 4 5] ] ...

Subsets 1 Problem

Problem Given a set of distinct integers/characters, S, return all possible subsets. OR Given an integer array nums of unique elements, return all possible subsets (the power set). Examples If we’re given a set of integers such that S = {1, 2, 3}, how can we find all the subsets of that set? For example, given S, the set of all subsets i.e. P(S) we get are {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, and {1, 2, 3}. Here is {} is empty set denoted by Φ. ...

Combination Sum 3 - Find k numbers summing up to n

Problem Find all valid combinations of k numbers that sum up to n such that the following conditions are true: Only numbers 1 through 9 are used. Each number is used at most once. Return a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order. Examples Example 1: Input: k = 3, n = 7 Output: [ [1,2,4] ] Explanation: 1 + 2 + 4 = 7 There are no other valid combinations. ...

Combination Sum 2 - Cant Reuse same element

Problem 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 combinations. Examples Example 1: Input: candidates = [10,1,2,7,6,1,5], target = 8 Output: [ [1,1,6], [1,2,5], [1,7], [2,6] ] ...

Combination Sum 1 Problem

Problem Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different. It is guaranteed that the number of unique combinations that sum up to target is less than 150 combinations for the given input. ...

Letter Combinations of a Phone Number Problem

Problem 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. ...

List Combinations - Generate unique combinations from list selecting 1 element from each

Problem Given a list of lists containing elements, write a function that prints out the permutations of of the elements such that, each of the permutation set contains only 1 element from each list and there are no duplicates in the list of permutation sets. Examples Example 1: Input: lists = [ [a1, b1, c1], [a2, b2] ] Output: [ [a1, a2], [a1, b2], [b1, a2], [b1, b2], [c1, a2], [c1, b2] ] Explanation: Note that [a1, a2] is same as [a2, a1] in terms of combination, though they are separate permutation. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy