Skip to main content

Posts

Showing posts with the label Find a string Hackerrank Solution Python

Find a string Hackerrank Solution Python

 Find a string Hackerrank Solution Python For Explanation Watch Video: Sample Input ABCDCDC CDC Sample Output 2 Code: def  count_substring(string, sub_string):     c =  0     len_sub =  len (sub_string)      for  i  in   range ( len (string)- len (sub_string)+ 1 ):          if  string[i:i+len_sub]==sub_string:             c +=  1        return  c if  __name__ ==  '__main__' :     string =  input ().strip()     sub_string =  input ().strip()          count = count_substring(string, sub_string)      print (count)