Skip to main content
added 1209 characters in body
Source Link
Olivier Grégoire
  • 14.5k
  • 3
  • 33
  • 56

Java (JDK), 113 bytes

s->{int m=0,l=s.length(),t,L=0;for(;l>0;L=t>m?(m=t)-m+l:L)t=s.split("\\b[a-zA-Z]{"+l--+"}\\b").length;return-~L;} 

Try it online!Try it online!

Explanation

This basically splits the String on ascii words of all possible lengths to count them, and returns the max value of the count.

s->{ int m=0, // The maximum number of l=s.length(), // The length of ASCII letters, going from high to low t, // Declare a temp variable. L=0; // Initialize the most present length to 0. for( // Loop ; l>0; // On each length, going down L=t>m?(m=t)-m+l:L // If a count is higher than the max count, the new count becomes the max count and the most present length becomes the current length ) t= s.split("\\b[a-zA-Z]{"+l--+"}\\b") // Count the number of parts between or around words of length l // Also, decrement l .length; // Store the count into t return-~L; // Return L + 1 } 

Java (JDK), 113 bytes

s->{int m=0,l=s.length(),t,L=0;for(;l>0;L=t>m?(m=t)-m+l:L)t=s.split("\\b[a-zA-Z]{"+l--+"}\\b").length;return-~L;} 

Try it online!

Java (JDK), 113 bytes

s->{int m=0,l=s.length(),t,L=0;for(;l>0;L=t>m?(m=t)-m+l:L)t=s.split("\\b[a-zA-Z]{"+l--+"}\\b").length;return-~L;} 

Try it online!

Explanation

This basically splits the String on ascii words of all possible lengths to count them, and returns the max value of the count.

s->{ int m=0, // The maximum number of l=s.length(), // The length of ASCII letters, going from high to low t, // Declare a temp variable. L=0; // Initialize the most present length to 0. for( // Loop ; l>0; // On each length, going down L=t>m?(m=t)-m+l:L // If a count is higher than the max count, the new count becomes the max count and the most present length becomes the current length ) t= s.split("\\b[a-zA-Z]{"+l--+"}\\b") // Count the number of parts between or around words of length l // Also, decrement l .length; // Store the count into t return-~L; // Return L + 1 } 
Source Link
Olivier Grégoire
  • 14.5k
  • 3
  • 33
  • 56

Java (JDK), 113 bytes

s->{int m=0,l=s.length(),t,L=0;for(;l>0;L=t>m?(m=t)-m+l:L)t=s.split("\\b[a-zA-Z]{"+l--+"}\\b").length;return-~L;} 

Try it online!