in java question:
Write a static member function calledremoveLongestRepeatingSegment that takes a String argument. Themethod will return a new String by removing the logest segment thatcontains consequtively repeating characters.
public static void main(String []args){
String s=”1111222223333311111111444455552222”;
String res= removeLongestRepeatingSegment(s); will return“11112222233333444455552222”
}
public static String removeLongestRepeatingSegment(Strings){
Answer
public class Main {
public static String removeLongestRepeatingSegment(String s){
int first = 0, last = 0, max = 1, count = 1, temp = 0;
char curr = s.charAt(0);
for(int i=1; i<s.length(); i++)
{
if(s.charAt(i-1) == s.charAt(i))
count++;
else
{
if(max < count)
{
first = temp;
max
OR
OR