#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Urgent Help(please Solve In C)


    Given a string S, and a string T, find the length of the smallest substring of S which contains all the characters of T - in any order. If no such substring exists, print -1.

    Input:
    The first line consists of the string S.
    The next line consists of a single integer Q, the number of strings "T" that you would query for in S.
    Then follow Q lines, each consisting of a single string T.

    Output:
    Q lines, the answers to the Q queries.

    Constraints:
    1 <= |S| <= 100000
    1 <= Q <= 100
    1 <= |T| <= 1000
    All characters in the input are lowercase 'a'-'z'.

    Sample Input:
    aabcab
    2
    ac
    d

    Sample Output:
    2
    -1

    Time Limit:
    2s

    Memory Limit:
    64 MB
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,075
    Rep Power
    1802
    Getting someone to do the work for you is not really the point of this homework assignment. Where are you getting stuck? There are two aspects to this: The algorithm, and the C coding. What algorithm do you propose? How far have you got with teh coding?

IMN logo majestic logo threadwatch logo seochat tools logo