- Non-decreasing Subsequences
Given an integer array nums, return all the different possible non-decreasing subsequences of the given array with at least two elements. You may return the answer in any order.
var findSubsequences = function(nums) {
const res = []
function dfs(i, subseq) {
const last = subseq[subseq.length-1]
const visited = []
for (let j = i; j < nums.length; j++) {
if (visited[nums[j]] || nums[j] < last) continue
visited[nums[j]] = 1
const newSubseq = subseq.concat(nums[j])
if (newSubseq.length > 1) {
res.push(newSubseq)
}
dfs(j+1, newSubseq)
}
}
dfs(0, [])
return res
}