Cody

Problem 2487. Create Combination

Motivation: In many problems, we need to create combinations with the function nchoosek. In some cases, however, choices are limited in particular fields. This problem is an exercise based on this issue.

Problem statement: Given a vector v, create a combination matrix where an element on i-th column can not exceed v(i). All values of input vector will be of single digit.

Example:

v = [1 3 2];
Output =[
     1     1     1
     1     1     2
     1     2     1
     1     2     2
     1     3     1
     1     3     2 ];

Solution Stats

51.35% Correct | 48.65% Incorrect
Last solution submitted on Sep 15, 2019

Solution Comments