Skip to main content
added 7 characters in body
Source Link
user
  • 457
  • 2
  • 21
  • 71

Java (JDK), 129 bytes

Saved 10 bytes thanks to @ceilingcat!

s->{int m=0,z=s.length()+1,a[]=new int[z];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(;z-->0;m=a[z]>a[m]?z:m);return m;}; 

Try it online!


Explanation:

s -> { int m=0, //m is the index of the max element in a z=s.length()+1, //z is to avoid using a.length twice a[]=new int[z]; //Each index corresponds to a length, and the element at that index its frequency for(var x : s.split("[^a-zA-Z]+")) //Fill up the pigeonholes a[x.length()]++; for(; //Find the index of the max element/highest frequency/mode z-->0; //For every index from a.length to 0, m=a[z]>a[m]?z:m); //If the current element is greater than the current max frequency, change the mode length return m; //Return the length with the highest frequency }; 

Java (JDK), 129 bytes

Saved 10 bytes thanks to @ceilingcat!

s->{int m=0,z=s.length()+1,a[]=new int[z];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(;z-->0;m=a[z]>a[m]?z:m);return m;}; 

Try it online!

Java (JDK), 129 bytes

Saved 10 bytes thanks to @ceilingcat!

s->{int m=0,z=s.length()+1,a[]=new int[z];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(;z-->0;m=a[z]>a[m]?z:m);return m;}; 

Try it online!


Explanation:

s -> { int m=0, //m is the index of the max element in a z=s.length()+1, //z is to avoid using a.length twice a[]=new int[z]; //Each index corresponds to a length, and the element at that index its frequency for(var x : s.split("[^a-zA-Z]+")) //Fill up the pigeonholes a[x.length()]++; for(; //Find the index of the max element/highest frequency/mode z-->0; //For every index from a.length to 0, m=a[z]>a[m]?z:m); //If the current element is greater than the current max frequency, change the mode length return m; //Return the length with the highest frequency }; 
added 7 characters in body
Source Link
user
  • 457
  • 2
  • 21
  • 71

Java (JDK), 139129 bytes

Saved 10 bytes thanks to @ceilingcat!

s->{int m=0,a[]=new int[sz=s.length()+1];for+1,a[]=new int[z];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(int i=a.length;i;z-->0;m=a[i]>a[m]>0;m=a[z]>a[m]?iz:m);return m;}; 

Try it online!Try it online!

Java (JDK), 139 bytes

s->{int m=0,a[]=new int[s.length()+1];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(int i=a.length;i-->0;m=a[i]>a[m]?i:m);return m;}; 

Try it online!

Java (JDK), 129 bytes

Saved 10 bytes thanks to @ceilingcat!

s->{int m=0,z=s.length()+1,a[]=new int[z];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(;z-->0;m=a[z]>a[m]?z:m);return m;}; 

Try it online!

Source Link
user
  • 457
  • 2
  • 21
  • 71

Java (JDK), 139 bytes

s->{int m=0,a[]=new int[s.length()+1];for(var x:s.split("[^a-zA-Z]+"))a[x.length()]++;for(int i=a.length;i-->0;m=a[i]>a[m]?i:m);return m;}; 

Try it online!