Quick actions

cmd+k|ctrl+k

Navigation

Languages

longest prefix v2

Snippet info

Language

Python

Visibility

public

Author

krishnakanth

Created

2023-06-26T06:15:57.718423Z

Updated

2023-06-26T06:15:57.718423Z

s = list(input().split(" "))
res = ""
temp = s[0]
for i in range(1,len(s)):
    for j in range(len(s[i])):
        try:
            if(s[i][j] == temp[j]):
               
                res += s[i][j]
                print(s,res)
                
            else:
                temp = res
                res = ""
                break
        except IndexError:
            continue
   
        
    # if(i == len(s)-1) :
    print(res,temp)
    temp = res
    
    
    res = ""    
       
        
        
        
        
INFO