find a string hackereank

Solutions on MaxInterview for find a string hackereank by the best coders in the world

showing results for - "find a string hackereank"
Jonah
16 Jan 2019
1def count_substring(string, sub_string):
2    count=0  #initialise count variable
3    for i in range(0,len(string)):
4        if string[i:].startswith(sub_string): # basically it traverses from left to right and looks for occurence of substring
5            count+=1 #every time count will increase by 1
6
7    return count
Luca
31 Jan 2021
1#(method 1)
2import re
3def count_substring(string,sub_string)
4count = re.findall('(?='+sub_string+')',string)
5return len(count)
6
7# (method 2) lengthy but easier for beginners
8def count_substring(string, sub_string): 
9    zero=0
10    astring=string + "@"
11    sub_count=0
12    count=0
13    for i in range (len(astring)-1):
14        if astring[i]==sub_string[0]:
15            for j in range(1,len(sub_string)):
16                if astring[i+j]==sub_string[j]:
17                    sub_count+=1
18                elif astring[j+i]=='@':
19                    break
20            if sub_count==len(sub_string)-1:
21                count+=1
22            sub_count=0
23    return count
24
25
queries leading to this page
hackerrank find a string find a string hacker rnakin this challenge 2c the user enters a string and a substring you have to print the number of times that the substring occurs in the given string string traversal will take place from left to right 2c not from right to lefthackerrank in string solutioncount occurrences of substring in string python hackerrank solutionprint number of times the string strfind appears in the string 28first second parent city 29 hackerrankrookie compare strings hackerrank solution in pythonfind a string hackerrank solution explainationfind a string python hackerrank solutionfind a string hackerrank solution in python githubfind a string hackereankfind a string hackerrank solution python 3find a string hackerrankstrings hackerrank solutioncheck if the string phone start with string start and print the result hackerrankfind a string hackeranfind a string hacker rank solutioncomparing strings practice python hackerrank solutionfind a string heckerrankhackerrank in a string 21 hackerrank solution in javafind strings hackerrank solutionhackerrank python find a string solutionin this challenge 2c the user enters a string and a substring you have to print the number of times that the substring occurs in the given string string traversal will take place from left to right 2c not from right to left hackerrank solutions the first line of input contains the original string the next line contains the substring find a string hackerrank solution in pythonfind a string in a string python hackerrank solutionsolution hackerrank find a string find a string hackerrank solution in python 3find a string hackerankhackerrank hackerrank is a stringfind a string hackerrank solutionstring function calculation hackerrank solutionfind string hackerrank solutionhackerrank find a string solutioncount substring in python hackerrankfindsubstring in hackerrank solution pythonfind substring in hackerrank solution pythonfind a string hackereank