Skip to content
Advertisement

finding possible combination from a given number that starts and ends with common number within the string

**String looks like **

JavaScript

Possible number of combination is to be find where the number starts and ends with 1

for example

JavaScript

Advertisement

Answer

The following works for one interpretation of your question. It works by first finding the indices of the ones, looping over all pairs of those indices, and then slicing:

JavaScript

Output:

JavaScript

If all you want is the set of such numbers (without any duplicates) then the loop can add numbers to a set rather than print them.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement