Onehouse · OA
In processOnehouse.ai OA Technical Screen
Applied on LinkedIn, received a link from the recruiter for the OA a couple weeks after.
OA had one question, 1D DP, similar to Word Search on Leetcode
Spell Fragmentation Decoder
You have discovered an ancient magical scroll containing a long continuous string encodedString of mysterious characters. This string encodes a sequence of magical words that must be deciphered by splitting it into valid fragments. Fortunately, you also have a dictionary of known magical words that can help decode the scroll.
Your goal is to break the string into valid words using the dictionary and maximize the number of such words formed. Each time you find a word from the dictionary in the string (as a contiguous fragment), you may include it and continue recursively on the remaining part of the string.
Function Description
You need to implement the function maxWordsDecrypted to find the maximum number of valid words the string can be split into, using only the words in the dictionary.
Parameters:
encodedString(String): A string representing the encoded magical text. The length of this string is between1 ≤ length(encodedString) ≤ 100,000.dictionarySize(Int): An integernrepresenting the size of the dictionary. The value ofnis between1 ≤ n ≤ 30,000.wordDict(List of Strings): A list of strings where each string represents a valid magical word in the dictionary. The length of each word is between1 ≤ length(word) ≤ 100.
Return:
- An integer representing the maximum number of valid words the string can be broken into using words from the dictionary.
Input Format:
- The first line contains a string
encodedString(1 ≤ length of encodedString ≤ 100,000).
(Remaining input lines fordictionarySizeandwordDictare cut off below the scroll in the image.)
Sample Input 1 (from the right pane)
aaaa
1
a
Comments
0No comments yet — be the first to share what you know.