twitch 今天的 电面,湾区

就是如果 一个word的任何substring 被 highlight了, 整个word 就会被highlight

// input = {
//     "sentence": "My friend is mitbbs and your name is Jim.",
//     "matches": [
//         {
//             "start": 0,
//             "end": 2,
//             "should_highlight": False
//         },
//         {
//             "start": 14,
//             "end": 17,
//             "should_highlight": True
//         },
//         {
//             "start": 36,
//             "end": 39,
//             "should_highlight": True
//         }
//     ]
// }

// # should result in
// output = [
//     { "phrase": "My",     "result": False },
//     { "phrase": "friend", "result": False },
//     { "phrase": "is",     "result": False },
//     { "phrase": "mitbbs",  "result": True },
//     { "phrase": "and",    "result": False },
//     { "phrase": "your",   "result": False },
//     { "phrase": "name",   "result": False },
//     { "phrase": "is",     "result": False },
//     { "phrase": "Jim.", "result": True },
// ]

follow up 如果 matches 比较长,比如几乎和sentence 一样长, 怎么优化