这是一个小时的在线Video面试
Question:
We are building a system to analyze and display text. To start, we’d like to be able to display the text with a set of substrings highlighted. However, these substrings might overlap, and that’s a problem for HTML. We need to return the info necessary to insert the <b> and </b>
tags into the string without overlaps. Why are overlaps a problem? For instance, if you have the string “BANANA” and you search for “ANA” then you’ll find two overlapping occurrances of ANA. What information do you need to return in order to highlight the entire overlapping part? A second example. The strong to search is “BANANARANA-A-GOGO", and you want to highlight “ANA” and “GO”, this includes overlapping, adjoining and disjoint examples. How do you return all of the info necessary to highlight all of the matches?
Write a function that takes an input string and a set of substrings to highlight and returns a set of start/end positions that could be used to highlight the text.
Example :
getBoldRanges( “BANANARANA-A-GOGO”, [“ANA”, “GO”] ) return: [[1,5], [7,9], [13,16]]
做的时候,感觉完全没思路,大家有什么想法吗?