Generation

generate functionSun, 15 Jan 2023

how to find the subsequences of an array

vector<vector<int>> subsequences(vector<int> arr, int index){ if(index == 0){ return {{}, {arr[0]}}; } vector<vector<int>> smallAns = subsequences(arr, index - 1); int n = smallAns.size(); for(int i = 0; i < n; i++){ vector<int> v = smallAns[i]; v.push_back(arr[index]); smallAns.push_back(v); } return smallAns; }

Questions about programming?Chat with your personal AI assistant