3
int helper(string &num, int idx, string last) {4
// If we have made it to the end of num we have found a valid sequence5
if (num.size() == idx) {8
// The number of valid sequences starting from idx10
// If num[idx] == '0' then skip11
if (num[idx] != '0') {12
// Check all the possible numbers starting from idx13
for (int i = idx; i < num.size(); ++i) {14
// Construct the number15
string s = num.substr(idx, i - idx + 1);16
// If the number has less digits then the last number in the sequence it18
if (s.size() < last.size()) {21
// If the number is bigger or equal than the last (needs the size check23
if (last.size() < s.size() || s >= last) {24
// Do the recursice call with idx = i+1 and last=s25
count += helper(num, i + 1, s);32
int numberOfCombinations(string num) {33
return helper(num, 0, "0");