As reported: Morgan Stanley intern (2027 batch, on campus) technical interview (Sep 2026), after a discussion of the RAG architecture in the candidate's project: given
vec = ['a', 'b', 'c', 'd', 'e'], generate all strings of length ≥ 3 from these characters, using recursion / backtracking.
Given a list of distinct characters chars and an integer minLen, return every string that
- uses characters from
chars, each at most once, in the order they appear inchars, and - has length at least
minLen.
In the round, chars = ['a','b','c','d','e'] and minLen = 3.
Example 1
chars = ["a","b","c","d","e"], minLen = 3
-> ["abc","abcd","abcde","abce","abd","abde","abe","acd","acde","ace","ade","bcd","bcde","bce","bde","cde"]
16 strings: 10 of length 3, 5 of length 4, 1 of length 5.
Example 2
chars = ["a","b","c","d"], minLen = 2
-> ["ab","abc","abcd","abd","ac","acd","ad","bc","bcd","bd","cd"]
Clarifications
- Characters keep their relative order from
chars: withchars = ["a","b"],"ab"is generated but"ba"is not. - Return the strings in any order.
Constraints: 1 ≤ chars.length ≤ 15; the characters are distinct lowercase letters; 1 ≤ minLen ≤ chars.length.
Code runner format: one JSON value per line: chars (a list of one-letter strings), then minLen. Implement generateStrings(chars, minLen); the harness sorts your list and prints it.