Take two variables leftMost and rightMost, for each char in string 2 if index of char form string 2 in string 1 < leftMost, leftMost <- index if index of char from string 2 in string 1 > rightMost, rightMost <- index else continue with for loop
in the end, the difference between rightMost and leftMost (right-left) should be the max window size required. Since a window isn't being used, the order anyways doesn't matter. For example S1- H E L L O S2 LH left = length, right = 0 index of L in S1 is 2, which is <left and > right so left = right = 2 index of H in S1 is 0, which is <left but not > right, so now left = 0, right = 2, width = right - left+1 = 3 which is right since the window will be HEL -Minotauraus. On Jul 31, 6:39 am, srikanth sg <srikanthini...@gmail.com> wrote: > given two string , find the minimum width in string 1 containing the > all characters of string 2 , they may present in different order > string 1-HELLO > string 2- LE > answer-2 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.