Created
July 12, 2018 03:40
-
-
Save ekeitho/111c5c8f08a575d9eac62d687880cb79 to your computer and use it in GitHub Desktop.
Make all combinations of size k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun comboOfSizeK(word: String, r: Int): List<String> { | |
val list = arrayListOf<String>() | |
fun comobs(word: String, created: String, start: Int, end: Int, sizeOfCombo: Int) { | |
if (created.length == sizeOfCombo) { | |
list.add(created) | |
return | |
} | |
if (start > end) { | |
return | |
} | |
for(i in start..end) { | |
comobs(word,created + word[i], i+1, end, sizeOfCombo) | |
} | |
} | |
comobs(word, "", 0, word.length - 1, r) | |
return list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment