Subset Sum Problem 1 - Is there a subset?

Problem Given a list of integers S and a target number k, write a function that returns a true if there is subset of S that adds up to k. If such a subset cannot be made, then return false. Examples Example 1: nums = [2, 3, 5], k = 7 Output: true Explanation: Subset is [2, 5] ...

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

Subarrays vs Subsequences vs Subsets Definition

Definitions A subarray is a contiguous part of array and maintains relative ordering of elements. For an array/string of size n, there are n*(n+1)/2 non-empty subarrays/substrings. A subsequence maintain relative ordering of elements but may or may not be a contiguous part of an array. For a sequence of size n, we can have 2^n-1 non-empty sub-sequences in total. A subset MAY NOT maintain relative ordering of elements and can or cannot be a contiguous part of an array. For a set of size n, we can have (2^n) sub-sets in total. ...

Generate All Strings of n bits

Problem Generate All Strings of n bits, consider A[0..n-1] is an array of size n. Examples Example 1 n = 3 Output: [0, 0, 0] [1, 0, 0] [0, 1, 0] [1, 1, 0] [0, 0, 1] [1, 0, 1] [0, 1, 1] [1, 1, 1] ...

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