javascript
Valid Dictonary String - Bloomberg - Port Interactive Analytics - Full Stack - 11/8/21
// Start typing here// Start typing here
// Given an input of a dictionary of words and an input string that does not contain spaces, write a method that returns a string with spaces inserted accordingly.
Input: "bloombergisfun", ["bloom","bloomberg","is","fun"]
Output: "bloomberg is fun"
// Returns the shorter matching string
"bloombergisfun", ["bloom", "bloomberg","is","fun"]
"bloom berg is fun"
function spacedString(str, dictionary) {
let currentStr = ''
let words = [];
for(let i = 0; i < str.length; i++) {
currentStr ++ str[0]
if (dictionary.has(currentStr)) {
words.push(currentStr);
currentStr = '';
}
}
return words.join(' ');
}
Was this helpful?
Similar Posts
- Recommendations - Bloomberg - Port Interactive Analytics - Full Stack - 11/8/21
- Microsoft Fill Paint - Bloomberg - Port Interactive Analytics - Full Stack - 12/6/21
- Sort Tree - Bloomberg - Port Interactive Analytics - Front End - 12/6/21
- Van Ecks Sequence - Bloomberg - Asset Management AIM - Full Stack - 11/5/21
- Flexible UI Component - Bloomberg - Asset Management AIM - Full Stack - 12/6/21
- Compressed String with Sort - C3 AI - CRM - Full Stack - 11/11/21
- 2D Array Path - C3 AI - CRM - Full Stack - 11/11/21