Question: You are given a string S of length N and a string array Arr of tength M. Find the longest subsequence of S in which

You are given a string S of length N and a string array Arr of tength M.

Find the longest subsequence of S in which each substring of length 2 is

present in the string array Arr.

Notes:

A substring of a string is a contiguous subsequence of that string.

Make a function with parameters (String S, ListArr) and return an INTEGER denoting the longest subsequence of S in which each substring of length 2 is present in the string array Arr.

Sample Test cases:

Case 16abcdef1ab

OUTPUT2

Case 26abacaf2aaad

OUTPUT4

Case 36asgfsd4asagaffs

MAKE SURE ALL TEST CASES PROVIDED RUNS SUCCESSFULLY. THEN SURELY I WILL LIKE THE SOLUTION.

P.S: CODE IN ANY LANGUAGE, CAN TRY IN JAVA.

The first line contains an integer, N, denoting the length of the


The first line contains an integer, N, denoting the length of the string. The next line contains a string, S, denoting the given string. The next line contains an integer, M, denoting the number of elements in Arr. Each line i of the M subsequent lines (where 0

Step by Step Solution

3.43 Rating (143 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Public class LongestSubSequence public static void Mainstrin... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!