Find length of smallest window that contains all the characters of a string in another string

前端 未结 8 1523
不思量自难忘°
不思量自难忘° 2020-12-24 09:05

Recently i have been interviewed. I didn\'t do well cause i got stuck at the following question

suppose a sequence is given : A D C B D A B C D A C D and search seq

8条回答
  •  误落风尘
    2020-12-24 09:44

    I haven't read every answer here, but I don't think anyone has noticed that this is just a restricted version of local pairwise sequence alignment, in which we are only allowed to insert characters (and not delete or substitute them). As such it will be solved by a simplification of the Smith-Waterman algorithm that considers only 2 cases per vertex (arriving at the vertex either by matching a character exactly, or by inserting a character) rather than 3 cases. This algorithm is O(n^2).

提交回复
热议问题