{"id":"7d4915b6-a6a7-4e65-84c7-09b00ce82a92","name":"Friends Pairing","description":"1. You are given a number n, representing the number of friends.\r\n2. Each friend can stay single or pair up with any of it's friends.\r\n3. You are required to print the number of ways in which these friends can stay single or pair up.\r\nE.g.\r\n1 person can stay single or pair up in 1 way.\r\n2 people can stay singles or pair up in 2 ways. 12 => 1-2, 12.\r\n3 people (123) can stay singles or pair up in 4 ways. 123 => 1-2-3, 12-3, 13-2, 23-1.","inputFormat":"A number n","outputFormat":"A number representing the number of ways in which n friends can stay single or pair up.","constraints":"0 &lt;= n &lt;= 20","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std ;\n\n int main() {\n int n ;\n cin>>n ;\n // write your code here\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 // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def no_of_ways(N):\n # Write your code here \n \n \nif __name__ == '__main__':\n \n n = int(input()) ;\n print(no_of_ways(n))"}},"points":10,"difficulty":"easy","sampleInput":"4","sampleOutput":"10","questionVideo":"https://www.youtube.com/embed/SHDu0Ufjyk8?end=125","hints":[],"associated":[{"id":"0fee1bda-4170-462a-920a-342207dc9d11","name":"Friends Pairing problem is similar to which of the following?","slug":"friends-pairing-problem-is-similar-to-which-of-the-following","type":4},{"id":"1dfe3a9a-c6bf-464e-b95f-1b072ef8560a","name":"In how many ways 3 friends can be paired ?","slug":"in-how-many-ways-3-friends-can-be-paired","type":4},{"id":"6fa23f61-9b5d-4836-9e39-0cddc65bfb86","name":"Which type of array we will use in this question ?","slug":"which-type-of-array-we-will-use-in-this-question","type":4},{"id":"c0eb230b-68b4-442f-9c93-112f38abff82","name":"In dynamic programming, the technique of storing the previously calculated values is called __________","slug":"in-dynamic-programming-the-technique-of-storing-the-previously-calculated-values-is-called","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":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"f1dc4d97-16ad-42c2-9cb9-a11e9a1b652b","name":"Friends Pairing","slug":"friends-pairing","type":1}],"next":{"id":"38ee2d0a-acec-4453-88b2-e4a60d46f4f3","name":"Friends Pairing","type":3,"slug":"friends-pairing"},"prev":{"id":"2aca84b8-3c1e-4ad2-918c-b4b20c1394d6","name":"Tiling With M * 1 Tiles","type":3,"slug":"tiling-with-m-1-tiles"}}}

Friends Pairing

1. You are given a number n, representing the number of friends. 2. Each friend can stay single or pair up with any of it's friends. 3. You are required to print the number of ways in which these friends can stay single or pair up. E.g. 1 person can stay single or pair up in 1 way. 2 people can stay singles or pair up in 2 ways. 12 => 1-2, 12. 3 people (123) can stay singles or pair up in 4 ways. 123 => 1-2-3, 12-3, 13-2, 23-1.

{"id":"7d4915b6-a6a7-4e65-84c7-09b00ce82a92","name":"Friends Pairing","description":"1. You are given a number n, representing the number of friends.\r\n2. Each friend can stay single or pair up with any of it's friends.\r\n3. You are required to print the number of ways in which these friends can stay single or pair up.\r\nE.g.\r\n1 person can stay single or pair up in 1 way.\r\n2 people can stay singles or pair up in 2 ways. 12 => 1-2, 12.\r\n3 people (123) can stay singles or pair up in 4 ways. 123 => 1-2-3, 12-3, 13-2, 23-1.","inputFormat":"A number n","outputFormat":"A number representing the number of ways in which n friends can stay single or pair up.","constraints":"0 &lt;= n &lt;= 20","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std ;\n\n int main() {\n int n ;\n cin>>n ;\n // write your code here\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 // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def no_of_ways(N):\n # Write your code here \n \n \nif __name__ == '__main__':\n \n n = int(input()) ;\n print(no_of_ways(n))"}},"points":10,"difficulty":"easy","sampleInput":"4","sampleOutput":"10","questionVideo":"https://www.youtube.com/embed/SHDu0Ufjyk8?end=125","hints":[],"associated":[{"id":"0fee1bda-4170-462a-920a-342207dc9d11","name":"Friends Pairing problem is similar to which of the following?","slug":"friends-pairing-problem-is-similar-to-which-of-the-following","type":4},{"id":"1dfe3a9a-c6bf-464e-b95f-1b072ef8560a","name":"In how many ways 3 friends can be paired ?","slug":"in-how-many-ways-3-friends-can-be-paired","type":4},{"id":"6fa23f61-9b5d-4836-9e39-0cddc65bfb86","name":"Which type of array we will use in this question ?","slug":"which-type-of-array-we-will-use-in-this-question","type":4},{"id":"c0eb230b-68b4-442f-9c93-112f38abff82","name":"In dynamic programming, the technique of storing the previously calculated values is called __________","slug":"in-dynamic-programming-the-technique-of-storing-the-previously-calculated-values-is-called","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":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"f1dc4d97-16ad-42c2-9cb9-a11e9a1b652b","name":"Friends Pairing","slug":"friends-pairing","type":1}],"next":{"id":"38ee2d0a-acec-4453-88b2-e4a60d46f4f3","name":"Friends Pairing","type":3,"slug":"friends-pairing"},"prev":{"id":"2aca84b8-3c1e-4ad2-918c-b4b20c1394d6","name":"Tiling With M * 1 Tiles","type":3,"slug":"tiling-with-m-1-tiles"}}}
plane

Editor


Loading...

Friends Pairing

easy

1. You are given a number n, representing the number of friends. 2. Each friend can stay single or pair up with any of it's friends. 3. You are required to print the number of ways in which these friends can stay single or pair up. E.g. 1 person can stay single or pair up in 1 way. 2 people can stay singles or pair up in 2 ways. 12 => 1-2, 12. 3 people (123) can stay singles or pair up in 4 ways. 123 => 1-2-3, 12-3, 13-2, 23-1.

Constraints

0 <= n <= 20

Format

Input

A number n

Output

A number representing the number of ways in which n friends can stay single or pair up.

Example

Sample Input

4

Sample Output

10

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode