I was asked this question in a telephone interview for a summer internship, and I tried to come up with a solution to the complexity n * m (although this was also inaccurate) in Java.
I have a function that takes 2 lines, suppose "common" and "cmn". It should return True, based on the fact that "c", "m", "n" occur in the same order in "general". But if the arguments were βgeneralβ and βomnβ, they will return False, because although they occur in the same order, βmβ also appears after βoβ (which does not allow the pattern matching condition to be fulfilled)
I worked on this with the Hashmaps and Ascii arrays, but have not yet received a convincing solution! From what I have read so far, can this be related to Boyer-Moore or Levenshtein algorithms?
Waiting for a break in stackoverflow! :)
Change Some answers talk about shortening a word or creating a hash. But, in my understanding, this question cannot be done with hashesets, because the appearance / repetition of each character in the first line has its own meaning. PASS - "con", "cmn", "cm", "cn", "mn", "on", "co". FAIL, which may seem otherwise - "com", "omn", "mon", "om". This is FALSE / FAIL because "o" occurs earlier, as well as after "m". Another example: "google", "ole" will be PASS, but "google", "gol" will fail because "o" also appears before "g"!
java string algorithm
Madtest
source share