0
Find a substring in a string with no white space.
I have a string without any whitespace. How to find the maximum number of times a substring is repeated consecutively? For example:- String "hsjabcabcabchikabcabcng" Substring "abc" Output :- 3 (I tried using split function but I could not solve the problem rather made it more complicated) (Please help me with an idea that will help me start solving this problem the right way)
2 odpowiedzi
+ 1
You could use a while loop.
You define a counter variable as 1, and an index variable i.
Then you find the position of first substring and set i to it.
Then you increase counter by 1 'while' the next three letters (found by increasing i by the length of the substring) is the same as the substring.
+ 1
idea ? have you tried regex ?