Friends Pairing Problem

The task is to determine the total number of ways to pair up 'N' friends or leave some of them single, following these rules:

  1. Each friend can either pair with one other friend or stay single.
  2. A friend can only be part of one pair.

The result should be computed modulo 1000000007 (109+7) due to potentially large outputs.

Example:

Input:
T = 2
N = 3
N = 4
Output:
4
10
Constraints:
  • 1 <= T <= 100
  • 1 <= N <= 104
Note:
1. Compute the result using modulo 109 + 7.
2. Pairs {A, B} and {B, A} are identical.
Be the first one to answer
Add answer anonymously...
PayPal Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter