+ 1

How to find the length of the string for which any character in string is again exists?

like if give input-zbbbbbbbbbbzbbbbb then the output will be 10 because the length of the string between two z are10

24th Jan 2018, 5:16 PM
Nikhil Kohli
Nikhil Kohli - avatar
11 Answers
0
you could split the string on the letter "z" and then just call the length method on every element and return the highest
24th Jan 2018, 7:30 PM
Jeremy
Jeremy - avatar
+ 4
Well... That's why we are here, I'm grateful to discuss this logically. Let's wait for Nikhil comment.
24th Jan 2018, 7:46 PM
Fabio
+ 3
Should it count from any pair of characters? Or it searchs from an entered character? For example: *input = z *output=10 **input = s **output= 0
24th Jan 2018, 5:26 PM
Fabio
+ 3
Buddy, i've thought in a way to do it, but i saw your other post, and it has many many possibilities to find a couple without any criteria. Example: Input - abcdedcba There are 4 couples, and different lengths between them... Which of them should be the output?
24th Jan 2018, 7:30 PM
Fabio
+ 3
Jeremy is right... But how will the program know which letter split.
24th Jan 2018, 7:32 PM
Fabio
+ 3
In a comment up... Seems Nikhil wants the program to find the pair... Rather than tell to the program that counts the length between a character entered by the user.
24th Jan 2018, 7:42 PM
Fabio
+ 2
it count any pair of character
24th Jan 2018, 5:27 PM
Nikhil Kohli
Nikhil Kohli - avatar
+ 2
you either tell it or make it a fix character. if he just wants the longest substring with the same letter he could split the string on a character change and then return the longest substring
24th Jan 2018, 7:34 PM
Jeremy
Jeremy - avatar
+ 2
tbh i dont exactly know what he wants, in his original post there ate 10 b's which results in the output 10. in his comment there is only one letter (also a "b") but the output is 2
24th Jan 2018, 7:44 PM
Jeremy
Jeremy - avatar
+ 1
like input-zbzczbz output- 2
24th Jan 2018, 5:29 PM
Nikhil Kohli
Nikhil Kohli - avatar
+ 1
Ethical hacker asked to find vulnerabilities in transaction id input should a string(S) value only having lower case letters S[i]€[a,z] and K is the possible keys,if there exist at least one character C€[a,z] in each and every substring of S of length K key of ID is the minimum of such possible Ks. some test cases:- input-zbcde output-3 input-bbbbb output-1 input-zbzczbz output-2 in this question the 3rd case is not working for mine
25th Jan 2018, 5:31 AM
Nikhil Kohli
Nikhil Kohli - avatar