6 kyu

Simple Fun #245: Count Increasing Sequences

Description:

Task

Given integers n and k, find the number of strictly increasing sequences of length n consisting of positive integers not exceeding k.

If no such a strictly increasing sequence exist, return 0.

In this kata, we define a sequence of length 1 is a strictly increasing sequence.

Input/Output

[input] integer n

A positive integer.

1 ≤ n ≤ 20.

[input] integer k

A positive integer.

3 ≤ k ≤ 20.

[output] an integer

Example

For n = 2 and k = 3, the output should be 3.

There are 3 strictly increasing sequences of length 2:

[1, 2], [1, 3] and [2, 3].

For n = 1 and k = 4, the output should be 4.

There are 4 strictly increasing sequences of length 1:

[1], [2], [3] and [4].

For n = 3 and k = 4, the output should be 4.

There are 4 strictly increasing sequences of length 3:

[1, 2, 3], [1, 2, 4], [1, 3, 4] and [2, 3, 4].

For n = 4 and k = 3, the output should be 0.

There is no such a strictly increasing sequences of length 4.

Algorithms

Stats:

CreatedMay 4, 2017
PublishedMay 4, 2017
Warriors Trained174
Total Skips2
Total Code Submissions167
Total Times Completed59
JavaScript Completions59
Total Stars7
% of votes with a positive feedback rating93% of 29
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • docgunthrop Avatar
Ad