How to find longest set of contiguous substrings

Trying to figure out how to solve this problem. I'm not quite sure what technique to use / if there is an existing Leetcode problem that this is in.

/*
Given two strings s1 and s2 of same length and each character appears only once in a string. 
Find the maximum sized bag in the substring.
A Bag = same set of characters that appear together in both strings

s1 = "abcdef" 
s2 =  "apecdq" 

In this example,
function maxBag(s1, s2) should return 3 because "cde" and "ecd" is the largest bag of size 3

 */

Apparently there are various ways to do this, DP, Sliding Window.

Comments (0)