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.
Similar Kata:
Stats:
Created | May 4, 2017 |
Published | May 4, 2017 |
Warriors Trained | 174 |
Total Skips | 2 |
Total Code Submissions | 167 |
Total Times Completed | 59 |
JavaScript Completions | 59 |
Total Stars | 7 |
% of votes with a positive feedback rating | 93% of 29 |
Total "Very Satisfied" Votes | 26 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |