+ 2

How to get the minimum length of the strings in array of strings

like if we input-["abcd","ab","abd"] so it will return the output -2

25th Jan 2018, 4:38 AM
Nikhil Kohli
Nikhil Kohli - avatar
5 odpowiedzi
0
from functools import reduce mylist=['tres','57','fhhjjj','t'] # min=reduce(lambda f,s:min(len(f),len(s)),mylist) result=sorted(mylist,key=lambda x:len(x))[0] print(result)
25th Jan 2018, 2:49 PM
alterhu2020
alterhu2020 - avatar
+ 19
or //import java.util.Arrays; 1)use Arrays.sort (arrayname); 2)take out the first element with index 0 & print its length
25th Jan 2018, 5:10 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
Seems that you have your answer...
25th Jan 2018, 6:09 AM
Fabio
+ 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:30 AM
Nikhil Kohli
Nikhil Kohli - avatar