You are given an integer N representing N friends. Each friend can either stay single or pair up with one other friend. Your task is to find the total number of different ways the friends can remain single or be paired.
Each friend can be paired only once. Calculate and return the total number of possible arrangements.
Example 1
Input: N = 2
Output: 2
Explanation: The arrangements are: both single, or both paired together.
Example 2
Input: N = 3
Output: 4
Explanation: The arrangements are: all single, (1,2) pair, (1,3) pair, or (2,3) pair.
Example 3
Input: N = 4
Output: 10
Explanation: The arrangements include all single, one pair with two singles, or two separate pairs, giving a total of 10 different combinations.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2
2
3
4