`{"id":"b6adb086-8837-454f-a236-f22c993eca00","name":"Get Subsequence","description":"<p>1. You are given a string str. 2. Complete the body of getSS function - without changing signature - to calculate all subsequences of str. Use sample input and output to take idea about subsequences. Note -&gt; The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.</p>","inputFormat":"<p>A string str</p>","outputFormat":"<p>Contents of the arraylist containing subsequences as shown in sample output</p>","constraints":"<p>0 &lt;= str.length &lt;= 20</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\nvector<string> gss(string s){\r\n // write your code here\r\n \r\n}\r\n\r\nint main(){\r\n string s;\r\n cin >> s;\r\n vector<string> ans = gss(s);\r\n int cnt = 0;\r\n\r\n cout << ''['';\r\n for (string str : ans){\r\n if (cnt != ans.size() - 1)\r\n cout << str << \", \";\r\n else\r\n cout << str;\r\n cnt++;\r\n }\r\n cout << '']'';\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n public static ArrayList<String> gss(String str) {\r\n return null;\r\n }\r\n\r\n}"},"python":{"code":"s = input()\n\ndef getSS(s):\n #Write your code here\n \nans = getSS(s)\n\nprint(\"[\"+', '.join(ans) + \"]\")"}},"points":10,"difficulty":"easy","sampleInput":"abc","sampleOutput":"[, c, b, bc, a, ac, ab, abc]","questionVideo":"https://www.youtube.com/embed/Sa5PmCFF_zI","hints":[],"associated":[{"id":"1ad0da5b-0881-4dcc-83ea-19143086268e","name":"(Get subsequence) What is the total number of subsequences for a given string “abcd”?","slug":"get-subsequence-what-is-the-total-number-of-subsequences-for-a-given-string-abcd","type":4},{"id":"2a3e52ad-7bc3-4d42-9b27-f2a4388e2059","name":"(Get subsequence)What will be time complexity to calculate all the sub sequences of any given string?","slug":"get-subsequence-what-will-be-time-complexity-to-calculate-all-the-sub-sequences-of-any-given-string","type":4},{"id":"df6a766b-eccf-4de1-9bd2-d0d4d2d0d1f9","name":"(Get subsequence)Which is not a valid subsequence for string “abc”?","slug":"get-subsequence-which-is-not-a-valid-subsequence-for-string-abc","type":4},{"id":"fbf97273-479c-40f1-a48f-ad32702f11f8","name":"(Get subsequence) What is the first subsequence of string “abc” :-","slug":"get-subsequence-what-is-the-first-subsequence-of-string-abc","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"6299c966-535d-48bd-b598-a71cfd401f61","name":"Get Subsequence","slug":"get-subsequence","type":1}],"next":{"id":"a3882bca-cf16-477e-b2c6-fa4b4b824259","name":"Get Subsequence","type":3,"slug":"get-subsequence"},"prev":{"id":"390199fc-127e-4c58-9e6f-66d4c9020b34","name":"All Indices In An Array","type":3,"slug":"all-indices-in-an-array"}}}`

# Get Subsequence

<p>1. You are given a string str. 2. Complete the body of getSS function - without changing signature - to calculate all subsequences of str. Use sample input and output to take idea about subsequences. Note -&gt; The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.</p>

`{"id":"b6adb086-8837-454f-a236-f22c993eca00","name":"Get Subsequence","description":"<p>1. You are given a string str. 2. Complete the body of getSS function - without changing signature - to calculate all subsequences of str. Use sample input and output to take idea about subsequences. Note -&gt; The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.</p>","inputFormat":"<p>A string str</p>","outputFormat":"<p>Contents of the arraylist containing subsequences as shown in sample output</p>","constraints":"<p>0 &lt;= str.length &lt;= 20</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\nvector<string> gss(string s){\r\n // write your code here\r\n \r\n}\r\n\r\nint main(){\r\n string s;\r\n cin >> s;\r\n vector<string> ans = gss(s);\r\n int cnt = 0;\r\n\r\n cout << ''['';\r\n for (string str : ans){\r\n if (cnt != ans.size() - 1)\r\n cout << str << \", \";\r\n else\r\n cout << str;\r\n cnt++;\r\n }\r\n cout << '']'';\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n public static ArrayList<String> gss(String str) {\r\n return null;\r\n }\r\n\r\n}"},"python":{"code":"s = input()\n\ndef getSS(s):\n #Write your code here\n \nans = getSS(s)\n\nprint(\"[\"+', '.join(ans) + \"]\")"}},"points":10,"difficulty":"easy","sampleInput":"abc","sampleOutput":"[, c, b, bc, a, ac, ab, abc]","questionVideo":"https://www.youtube.com/embed/Sa5PmCFF_zI","hints":[],"associated":[{"id":"1ad0da5b-0881-4dcc-83ea-19143086268e","name":"(Get subsequence) What is the total number of subsequences for a given string “abcd”?","slug":"get-subsequence-what-is-the-total-number-of-subsequences-for-a-given-string-abcd","type":4},{"id":"2a3e52ad-7bc3-4d42-9b27-f2a4388e2059","name":"(Get subsequence)What will be time complexity to calculate all the sub sequences of any given string?","slug":"get-subsequence-what-will-be-time-complexity-to-calculate-all-the-sub-sequences-of-any-given-string","type":4},{"id":"df6a766b-eccf-4de1-9bd2-d0d4d2d0d1f9","name":"(Get subsequence)Which is not a valid subsequence for string “abc”?","slug":"get-subsequence-which-is-not-a-valid-subsequence-for-string-abc","type":4},{"id":"fbf97273-479c-40f1-a48f-ad32702f11f8","name":"(Get subsequence) What is the first subsequence of string “abc” :-","slug":"get-subsequence-what-is-the-first-subsequence-of-string-abc","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"6299c966-535d-48bd-b598-a71cfd401f61","name":"Get Subsequence","slug":"get-subsequence","type":1}],"next":{"id":"a3882bca-cf16-477e-b2c6-fa4b4b824259","name":"Get Subsequence","type":3,"slug":"get-subsequence"},"prev":{"id":"390199fc-127e-4c58-9e6f-66d4c9020b34","name":"All Indices In An Array","type":3,"slug":"all-indices-in-an-array"}}}`

Editor

Loading...

# Get Subsequence

easy

1. You are given a string str. 2. Complete the body of getSS function - without changing signature - to calculate all subsequences of str. Use sample input and output to take idea about subsequences. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

## Constraints

0 <= str.length <= 20

## Format

A string str

### Output

Contents of the arraylist containing subsequences as shown in sample output

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}abc`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}[, c, b, bc, a, ac, ab, abc]`

Question Video

Discussions

Show Discussion

Related Resources