<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,6,7,7]
<strong>Output:</strong> [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,4,3,2,1]
<strong>Output:</strong> [[4,4]]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 15</code></li>
	<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
</ul>

class Solution {
public:
    // Function to find all the increasing subsequences in the given vector.
    vector<vector<int>> findSubsequences(vector<int>& nums) {
        vector<vector<int>> subsequences;
        vector<int> currentSubsequence;
        backtrack(0, INT_MIN, nums, currentSubsequence, subsequences); // Assuming -1000 is a lower bound, we use INT_MIN
        return subsequences;
    }

private:
    // Uses backtracking to find all subsequences.
    // u is the current index in nums.
    // last is the last number added to the current subsequence.
    // nums is the input array of numbers.
    // currentSubsequence holds the current subsequence being explored.
    // subsequences is the collection of all valid subsequences found.
    void backtrack(int index, int lastNumber, vector<int>& nums, vector<int>& currentSubsequence, vector<vector<int>>& subsequences) {
        if (index == nums.size()) { // Base case: reached the end of nums
            if (currentSubsequence.size() > 1) { // If the subsequence has more than 1 element, add it to the answer.
                subsequences.push_back(currentSubsequence);
            }
            return;
        }
        // If the current number can be added to the subsequence according to the problem definition (non-decreasing order)
        if (nums[index] >= lastNumber) {
            currentSubsequence.push_back(nums[index]); // Add number to the current subsequence.
            backtrack(index + 1, nums[index], nums, currentSubsequence, subsequences); // Recursively call with next index.
            currentSubsequence.pop_back(); // Backtrack: remove the number from current subsequence.
        }
        // If current number is not equal to the last number added to the subsequence, continue to next index.
        // This avoids duplicates in the subsequences list.
        if (nums[index] != lastNumber) { 
            backtrack(index + 1, lastNumber, nums, currentSubsequence, subsequences); // Recursively call with next index.
        }
    }
};
18270