#Java 10, (削除) 212 (削除ここまで)(削除) 211 (削除ここまで)(削除) 196 (削除ここまで)(削除) 195 (削除ここまで)(削除) 146 (削除ここまで) 143 bytes
Java 10, (削除) 212 (削除ここまで)(削除) 211 (削除ここまで)(削除) 196 (削除ここまで)(削除) 195 (削除ここまで)(削除) 146 (削除ここまで) 143 bytes
#Java 10, (削除) 212 (削除ここまで)(削除) 211 (削除ここまで)(削除) 196 (削除ここまで)(削除) 195 (削除ここまで)(削除) 146 (削除ここまで) 143 bytes
Java 10, (削除) 212 (削除ここまで)(削除) 211 (削除ここまで)(削除) 196 (削除ここまで)(削除) 195 (削除ここまで)(削除) 146 (削除ここまで) 143 bytes
#Java 10, (削除) 212 (削除ここまで) (削除) 211 (削除ここまで) (削除) 196 (削除ここまで) (削除) 195 (削除ここまで) 146(削除) 146 (削除ここまで) 143 bytes
s->n->{String r="",t;for(int m=0,c,j,i=0;i<si=s.length();i-n;i++->n;)for(c=0,j=-1;(j=s.indexOf(t=s.substring(i-n,i+ni),j+1))>=0;)if(++c>m){m=c;r=t;}return r;}
-15 bytes by outputting the substrings with their count, which is allowed.
-1 byte thanks to @ceilingcat.
-4952 bytes thanks to @OlivierGrégoire.
s->n->{ // Method with String and Integer parameters and String return-type
String r="", // Result-String, starting empty
t; // Temp-String
for(int m=0, // Largest count, starting at 0
c, // Temp count integer
j, // Temp index integer
i // Index-integer `i`
=0;i<s=s.length();i-n;i++->n;)
// Loop `i` in the range [0, length (input-length, n)n]:
for(c=0, // Reset the temp-count to 0
j=-1; // And the temp-index integer to -1
(j=s.indexOf(t=s.substring(i-n,i+ni)
// Set String `t` to a substring of the input-String in the range [i-n,i+ni)
j+1))// Set the temp-index `j` to the index of String `t` in the input-String,
// only looking at the trailing portion after index `j+1`
>=0;) // And continue looping as long as long as that substring is found
if(++c>m){// If the temp-count + 1 is larger than the current largest count:
m=c; // Set this current largest count to this temp-count + 1
r=t;} // And the result-String to this temp-String
return r;} // After the nested loops, return the result-String
#Java 10, (削除) 212 (削除ここまで) (削除) 211 (削除ここまで) (削除) 196 (削除ここまで) (削除) 195 (削除ここまで) 146 bytes
s->n->{String r="",t;for(int m=0,c,j,i=0;i<s.length()-n;i++)for(c=0,j=-1;(j=s.indexOf(t=s.substring(i,i+n),j+1))>=0;)if(++c>m){m=c;r=t;}return r;}
-15 bytes by outputting the substrings with their count, which is allowed.
-1 byte thanks to @ceilingcat.
-49 bytes thanks to @OlivierGrégoire.
s->n->{ // Method with String and Integer parameters and String return-type
String r="", // Result-String, starting empty
t; // Temp-String
for(int m=0, // Largest count, starting at 0
c, // Temp count integer
j, // Temp index integer
i // Index-integer `i`
=0;i<s.length()-n;i++)
// Loop `i` in the range [0, length - n):
for(c=0, // Reset the temp-count to 0
j=-1; // And the temp-index integer to -1
(j=s.indexOf(t=s.substring(i,i+n)
// Set String `t` to a substring of the input-String in the range [i,i+n)
j+1))// Set the temp-index `j` to the index of String `t` in the input-String,
// only looking at the trailing portion after index `j+1`
>=0;) // And continue looping as long as long as that substring is found
if(++c>m){// If the temp-count + 1 is larger than the current largest count:
m=c; // Set this current largest count to this temp-count + 1
r=t;} // And the result-String to this temp-String
return r;} // After the nested loops, return the result-String
#Java 10, (削除) 212 (削除ここまで) (削除) 211 (削除ここまで) (削除) 196 (削除ここまで) (削除) 195 (削除ここまで) (削除) 146 (削除ここまで) 143 bytes
s->n->{String r="",t;for(int m=0,c,j,i=s.length();i-->n;)for(c=0,j=-1;(j=s.indexOf(t=s.substring(i-n,i),j+1))>=0;)if(++c>m){m=c;r=t;}return r;}
-15 bytes by outputting the substrings with their count, which is allowed.
-1 byte thanks to @ceilingcat.
-52 bytes thanks to @OlivierGrégoire.
s->n->{ // Method with String and Integer parameters and String return-type
String r="", // Result-String, starting empty
t; // Temp-String
for(int m=0, // Largest count, starting at 0
c, // Temp count integer
j, // Temp index integer
i // Index-integer `i`
=s.length();i-->n;)
// Loop `i` in the range (input-length, n]:
for(c=0, // Reset the temp-count to 0
j=-1; // And the temp-index integer to -1
(j=s.indexOf(t=s.substring(i-n,i)
// Set String `t` to a substring of the input-String in the range [i-n,i)
j+1))// Set the temp-index `j` to the index of String `t` in the input-String,
// only looking at the trailing portion after index `j+1`
>=0;) // And continue looping as long as long as that substring is found
if(++c>m){// If the temp-count + 1 is larger than the current largest count:
m=c; // Set this current largest count to this temp-count + 1
r=t;} // And the result-String to this temp-String
return r;} // After the nested loops, return the result-String
#Java 10, (削除) 212 (削除ここまで) (削除) 211 (削除ここまで) 196(削除) 196 (削除ここまで)(削除) 195 (削除ここまで) 146 bytes
import java.util.*;ss->n->{var m=newString HashMap<Stringr="",Long>();fort;for(int l=sm=0,c,j,i=0;i<s.length()-n+1;l-->0;n;i++)mfor(c=0,j=-1;(j=s.mergeindexOf(st=s.substring(li,l+ni+n),1L,Long::sumj+1);return m.entrySet().stream(>=0;).max(Map.Entry.comparingByValueif()++c>m);{m=c;r=t;}return r;}
-15 bytes by outputting the substrings with their count, which is allowed .
-1 byte thanks to @ceilingcat.
-49 bytes thanks to @OlivierGrégoire.
import java.util.*; // Required import for HashMap and Map
s->n->{ // Method with String and Integer parameters and OptionalString return-type
String r="", // Result-String, starting empty
t; // String-Integer Key-Value pair returnTemp-typeString
var m=newfor(int HashMap<Stringm=0,Long>();
// Largest count, starting at 0
c, // ATemp key-valuecount mapinteger
for String-Long pairs for the count per substring
for(intj, l=s.length()-n+1;l-->0;)
// Temp index integer
i // Loop `l` in the range (input_lengthIndex-n+1,integer 0]:`i`
m.merge(s =0;i<s.substringlength(l,l+n),-n;i++)
// Get theLoop substring`i` in the index-range [l[0, l+n)length as- keyn):
1for(c=0,Long::sum);
// Reset the temp-count to 0
j=-1; // And addthe ittemp-index integer to the-1
map by either starting at 1, or adding 1(j=s.indexOf(t=s.substring(i,i+n)
// Set String //`t` to dependinga onsubstring whetherof the keyinput-value pairString alreadyin existsthe orrange not[i,i+n)
return m.entrySet() j+1))// Then convertSet the Maptemp-index `j` to athe Setindex of Key-ValueString pairs`t` in the input-String,
.stream() // Convert that// Set to aonly Stream
looking at the trailing portion after index `j+1`
.max( >=0;) // Get theAnd maximumcontinue oflooping thatas streamlong by:
as long as that substring is found
if(++c>m){// Map.Entry.comparingByValue())
If the temp-count + 1 is larger than the current largest count:
m=c; // Looking at theSet valuesthis (thecurrent counts)largest count to this temp-count + 1
r=t;} // And the result-String to this temp-String
return r;} // And returnAfter thisthe Optionalnested key-valueloops, pairreturn asthe result-String
#Java 10, (削除) 212 (削除ここまで) (削除) 211 (削除ここまで) 196 bytes
import java.util.*;s->n->{var m=new HashMap<String,Long>();for(int l=s.length()-n+1;l-->0;)m.merge(s.substring(l,l+n),1L,Long::sum);return m.entrySet().stream().max(Map.Entry.comparingByValue());}
-15 bytes by outputting the substrings with their count, which is allowed.
import java.util.*; // Required import for HashMap and Map
s->n->{ // Method with String and Integer parameters and Optional
// String-Integer Key-Value pair return-type
var m=new HashMap<String,Long>();
// A key-value map for String-Long pairs for the count per substring
for(int l=s.length()-n+1;l-->0;)
// Loop `l` in the range (input_length-n+1, 0]:
m.merge(s.substring(l,l+n),
// Get the substring in the index-range [l, l+n) as key
1,Long::sum);
// And add it to the map by either starting at 1, or adding 1,
// depending on whether the key-value pair already exists or not
return m.entrySet() // Then convert the Map to a Set of Key-Value pairs
.stream() // Convert that Set to a Stream
.max( // Get the maximum of that stream by:
Map.Entry.comparingByValue())
// Looking at the values (the counts)
// And return this Optional key-value pair as result
#Java 10, (削除) 212 (削除ここまで) (削除) 211 (削除ここまで) (削除) 196 (削除ここまで)(削除) 195 (削除ここまで) 146 bytes
s->n->{String r="",t;for(int m=0,c,j,i=0;i<s.length()-n;i++)for(c=0,j=-1;(j=s.indexOf(t=s.substring(i,i+n),j+1))>=0;)if(++c>m){m=c;r=t;}return r;}
-15 bytes by outputting the substrings with their count, which is allowed .
-1 byte thanks to @ceilingcat.
-49 bytes thanks to @OlivierGrégoire.
s->n->{ // Method with String and Integer parameters and String return-type
String r="", // Result-String, starting empty
t; // Temp-String
for(int m=0, // Largest count, starting at 0
c, // Temp count integer
j, // Temp index integer
i // Index-integer `i`
=0;i<s.length()-n;i++)
// Loop `i` in the range [0, length - n):
for(c=0, // Reset the temp-count to 0
j=-1; // And the temp-index integer to -1
(j=s.indexOf(t=s.substring(i,i+n)
// Set String `t` to a substring of the input-String in the range [i,i+n)
j+1))// Set the temp-index `j` to the index of String `t` in the input-String,
// only looking at the trailing portion after index `j+1`
>=0;) // And continue looping as long as long as that substring is found
if(++c>m){// If the temp-count + 1 is larger than the current largest count:
m=c; // Set this current largest count to this temp-count + 1
r=t;} // And the result-String to this temp-String
return r;} // After the nested loops, return the result-String