Given a string 'abc', find all distinct subsequence combinations of it.
The algorithm breaks down the string character by character, starting from the end. At each step, it considers all the substrings found so far, and then creates new substrings by adding the current character to them. This process continues until all possible combinations are explored.
def combine(s): if len(s) == 0: return [] l = combine(s[:-1]) return l + [x + s[-1] for x in l] + [s[-1]] s = 'abc' print(combine(s))
function combine(s) { if (s.length === 0) { return []; } const l = combine(s.slice(0, -1)); return [...l, ...l.map(x => x + s.slice(-1)), s.slice(-1)]; } const str = 'abc'; console.log(combine(str));