25- String subsequences
String subsequences
Description
Given a string str, create a function that returns all its possible subsequences, the order doesn't matter.
Example 1:
- Input: str = "abcd"
- Output: ["abcd", "abc", "abd", "ab", "acd", "ac", "ad", "a", "bcd", "bc", "bd", "b", "cd", "c", "d", ""]
- Explanation:
Try some input:
str
=
Expected output:
Try to solve:
Select a language:
Solution:
Code:
Select a language:
Python code:
In case the code doesn't appear: click here
Time complexity: O(n.2^n)
Space complexity: O(n.2^n)
Java code:
In case the code doesn't appear: click here
Time complexity: O(n.2^n)
Space complexity: O(n.2^n)
C++ code:
In case the code doesn't appear: click here
Time complexity: O(n.2^n)
Space complexity: O(n.2^n)
JavaScript code:
In case the code doesn't appear: click here
Time complexity: O(n.2^n)
Space complexity: O(n.2^n)
Frequently asked questions:
No questions yet.
You can ask a question in comment section below.
0 comments