Find a string I think this solution could work, but in my opinion it's a bit unoptimized. Let's say in the sample test case: 'ABCDCDC' 'CDC', what your code does is that: s[0:0+3], s[1:1+3], s[2:2+3], ..., s[7:7+3]. The s[5:5+3] up to s[7:7+3] woul...
1if__name__=='__main__':2n =int(input())3arr =map(int, input().split())4print(sorted(list(set(arr)))[-2])
Solutions to few Hackerrank problems. Contribute to ubaidsworld/HackerRank-Python development by creating an account on GitHub.
string in Python How to create a dictionary in Python How to create a virtual environment in Python How to declare a variable in Python How to install matplotlib in Python How to install OpenCV in Python How to print in same line in Python How to read JSON file in Python How to read ...
Sometimes you will encounter the "Cannot find package" error (even though GOPATH is set) when building a Golang module. In this article, we will explain why it happens and how we can solve that error. Solution 1: Update your project structure First of all, you have to check if your ...
1. string[0:3] == sub_string if yes then sum will be 1. counter will be 1. counter will always incremented after the if statement. In this case not. so we end up with sum = 0 and counter = 1 string[1:4] == sub_string if yes then sum will incremented by 1, counter always...
Find a string one more one liner, though less efficient than yours. return[string[x:x+len(sub_string)]forxinrange(len(string)-len(sub_string)+1)].count(sub_string) i(len(string)))if(string[i:i+len(sub_string)]==sub_string))summ+=1...
Find a string Using List Comprehension: string, substring = (input().strip(), input().strip()) print(sum([ 1 for i in range(len(string)-len(substring)+1) if string[i:i+len(substring)] == substring]))
Find a string This is my code, why you need two for loops and make this complex? This is my code: string, substring = (input().strip(),input().strip) count = 0 for i in range(0, len(string)-len(substring)+1): if string[i:i+len(substring)]==substring: count+=1 return ...