Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-053

Bell Number

Problem

Compute the n-th Bell number, the number of ways to partition a set of n items into any number of nonempty blocks.

Use B(n) = sum over k of S(n, k), where S is the Stirling number of the second kind. Return 0 for negative n.

Hint

Sum the Stirling second-kind numbers over all block counts.

Test cases

case 1
in: [0]
expected: 1
case 2
in: [1]
expected: 1
case 3
in: [3]
expected: 5
case 4
in: [5]
expected: 52
case 5
in: [7]
expected: 877
Starter codePython
import math


def bell_number(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor