InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Shortest common superstring

Problem Setter: raghav_aggiwal Problem Tester: dhruvi

Given a set of strings, A of length N.

Return the length of smallest string which has all the strings in the set as substring.

Input Format:

The first and the only argument has an array of strings, A.

Output Format:

Return an integer representing the minimum possible length of the resulting string.


1 <= N <= 18
1 <= A[i] <= 100


Input 1:
    A = ["aaaa", "aa"]

Output 1:

Explanation 1:
    Shortest string: "aaaa"

Input 2:
    A = ["abcd", "cdef", "fgh", "de"]

Output 2:

Explanation 2:
    Shortest string: "abcdefgh"
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Shortest common superstring on Interview Code Editor
Sign Up
to access hints and editorial solutions for Shortest common superstring
Asked In:


Click here to start solving coding interview questions