Solutions for Find the Index

    • @AaronSkake
    • @Daniel, submitted in Python 3, achived 100% score
    import json
    def isSubstring(s1, s2):
        M = len(s1)
        N = len(s2)
    
        # A loop to slide pat[] one by one 
        for i in range(N - M + 1):
    
            # For current index i,
            # check for pattern match 
            for j in range(M):
                if (s2[i + j] != s1[j]):
                    break
    
            if j + 1 == M :
                return i
    
        return -1
    def solve(x,y):
        res = isSubstring(x, y)
        if res == -1 :
            return "Not present"
        else:
            return "Present at index " + str(res)