package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 830. Positions of Large Groups
 *
 * In a string S of lowercase letters, these letters form consecutive groups of the same character.
 * For example, a string like S = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy".
 * Call a group large if it has 3 or more characters.  We would like the starting and ending positions of every large group.
 * The final answer should be in lexicographic order.
 *
 * Example 1:
 * Input: "abbxxxxzzy"
 * Output: [[3,6]]
 * Explanation: "xxxx" is the single large group with starting  3 and ending positions 6.
 *
 * Example 2:
 * Input: "abc"
 * Output: []
 * Explanation: We have "a","b" and "c" but no large group.
 *
 * Example 3:
 * Input: "abcdddeeeeaabbbcd"
 * Output: [[3,5],[6,9],[12,14]]
 *
 * Note:  1 <= S.length <= 1000
 */
public class _830 {
  public static class Solution1 {
    public List<List<Integer>> largeGroupPositions(String S) {
      List<List<Integer>> result = new ArrayList<>();
      char[] chars = S.toCharArray();
      for (int i = 0; i < chars.length; ) {
        char first = chars[i];
        int j = i + 1;
        while (j < chars.length && first == chars[j]) {
          j++;
        }
        if ((j - i) >= 3) {
          result.add(Arrays.asList(i, j - 1));
        }
        i = j;
      }
      return result;
    }
  }
}

@@ -110,798 +110,8 @@
 t;%0A%0A
-/**%0A * 830. Positions of Large Groups%0A *%0A * In a string S of lowercase letters, these letters form consecutive groups of the same character.%0A * For example, a string like S = %22abbxxxxzyy%22 has the groups %22a%22, %22bb%22, %22xxxx%22, %22z%22 and %22yy%22.%0A * Call a group large if it has 3 or more characters.  We would like the starting and ending positions of every large group.%0A * The final answer should be in lexicographic order.%0A *%0A * Example 1:%0A * Input: %22abbxxxxzzy%22%0A * Output: %5B%5B3,6%5D%5D%0A * Explanation: %22xxxx%22 is the single large group with starting  3 and ending positions 6.%0A *%0A * Example 2:%0A * Input: %22abc%22%0A * Output: %5B%5D%0A * Explanation: We have %22a%22,%22b%22 and %22c%22 but no large group.%0A *%0A * Example 3:%0A * Input: %22abcdddeeeeaabbbcd%22%0A * Output: %5B%5B3,5%5D,%5B6,9%5D,%5B12,14%5D%5D%0A *%0A * Note:  1 %3C= S.length %3C= 1000%0A */%0A
 publ
@@ -126,16 +126,18 @@
  _830 %7B%0A
+  
   public
@@ -162,24 +162,28 @@
 tion1 %7B%0A    
+   
+ 
 public List%3C
@@ -225,24 +225,30 @@
 String S) %7B%0A
+      
       List%3CL
@@ -291,24 +291,30 @@
 %3C%3E();%0A      
+ 
+     
 char%5B%5D chars
@@ -339,16 +339,22 @@
 ;%0A      
+  
+    
 for (int
@@ -379,24 +379,32 @@
 length; ) %7B%0A
+        
         char
@@ -430,16 +430,24 @@
         
+  
+      
 int j = 
@@ -453,16 +453,24 @@
  i + 1;%0A
+        
         
@@ -513,24 +513,34 @@
 chars%5Bj%5D) %7B%0A
+          
           j+
@@ -542,34 +542,50 @@
    j++;%0A        
+    
-%7D%0A
+    %7D%0A        
         if ((j -
@@ -606,16 +606,26 @@
         
+  
+        
 result.a
@@ -661,26 +661,39 @@
         
+      
-%7D%0A
+  %7D%0A     
         
 i = j;%0A 
@@ -684,16 +684,19 @@
         
+   
 i = j;%0A 
@@ -696,26 +696,38 @@
  = j;%0A      
+    
-%7D%0A
+  %7D%0A      
       return
@@ -739,16 +739,22 @@
 lt;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 830