Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I guess I don't understand the question actually - is it return every potential word inside of a word and we accept that there is left over fragments that are not words, or does it have to make sure you do not have any left over fragments?

The problem as described:

“Write a function that given a string, determines if it’s a concatenation of two dictionary words.”

given that description I think you can't have left over fragments. But the code seems to allow fragments (don't know Python). Also it just returns a boolean? So we just need to know if there is two words contained within our word within the dictionary.

If that's the case, and the "dictionary" is an actual dictionary used by humans (they mean like a Dictionary like The Oxford American Dictionary right?), then, because the letters of a word are considered nouns (that is to say the letter b is a noun - Merriam-Webster https://www.merriam-webster.com/dictionary/b) then any word with more than one letter is a concatenation of two words. Which is anyway stupid because no one cares about concatenations of words, people care about compound words and this is not how you would find compound words.

I bet that's not what they want to hear though. I generally do really bad on questions.



I read it as asking for a function that takes a string and returns a "true" if it's a word comprised of two words and a "false" if it's not. So:

  "lampshade" => true
  "grip" => false
  "gripshell" => true 
  "fhtagnblue" => false
  "timeblue" => true


yes that's how I first read it but I got less sure that was meant as I read the rest.

For example it looks to me like it thinks fhtagnblue which has the words tag and blue in it should return true? Maybe I'm reading things wrong - but if it should return true, thus allowing fragments, then every word with two letters or more would return true because every letter is a noun.

If it is as you said, which might be actually interesting thing to do and potentially even useful, I might not want to do it with a query this dictionary for a string and instead have actual access to the dictionary to work with since I figure an optimized solution can be made with binary search.

on edit: I mean considering Google's reputation for trick questions and logic gotchas I would probably just say "wow you guys really are like that" and write something like

if(!s) {return false;} s_array = s.split(""); return s_array.length > 1;


oops but then I just realized what if string has numbers in it. I guess I would spend time trying to catch the different edge cases in my understanding of the question and at the end he would be like this guy struggled and did it wrong, when I just think they don't know letters are nouns.

on edit: hmm, a number is also a noun so I guess if query(9) or query("9") worked wouldn't have a problem, but then if it didn't I would have to say hey your dictionary is broken and then there would probably be discussions. But since it is all just hypothetical I suppose I could assume that the dictionary isn't broken and so any trimmed string with more than two characters in it would still return true.


If it had numbers I think you could immediately assume it is not 2 words.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: