package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 784. Letter Case Permutation
 *
 * Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.
 * Return a list of all possible strings we could create.

 Examples:
 Input: S = "a1b2"
 Output: ["a1b2", "a1B2", "A1b2", "A1B2"]

 Input: S = "3z4"
 Output: ["3z4", "3Z4"]

 Input: S = "12345"
 Output: ["12345"]

 Note:

 S will be a string with length at most 12.
 S will consist only of letters or digits.

 */

public class _784 {
  public static class Solution1 {
    public List<String> letterCasePermutation(String S) {
      Set<String> result = new HashSet<>();
      result.add(S);
      for (int i = 0; i < S.length(); i++) {
        if (Character.isAlphabetic(S.charAt(i))) {
          Set<String> newResult = new HashSet<>();
          for (String word : result) {
            if (Character.isUpperCase(word.charAt(i))) {
              StringBuilder sb = new StringBuilder();
              for (int j = 0; j < i; j++) {
                sb.append(word.charAt(j));
              }
              sb.append(Character.toLowerCase(word.charAt(i)));
              for (int j = i + 1; j < word.length(); j++) {
                sb.append(word.charAt(j));
              }
              newResult.add(sb.toString());
            } else {
              StringBuilder sb = new StringBuilder();
              for (int j = 0; j < i; j++) {
                sb.append(word.charAt(j));
              }
              sb.append(Character.toUpperCase(word.charAt(i)));
              for (int j = i + 1; j < word.length(); j++) {
                sb.append(word.charAt(j));
              }
              newResult.add(sb.toString());
            }
          }
          result.addAll(newResult);
        }
      }
      return new ArrayList<>(result);
    }
  }
}

@@ -133,482 +133,8 @@
 t;%0A%0A
-/**%0A * 784. Letter Case Permutation%0A *%0A * Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.%0A * Return a list of all possible strings we could create.%0A%0A Examples:%0A Input: S = %22a1b2%22%0A Output: %5B%22a1b2%22, %22a1B2%22, %22A1b2%22, %22A1B2%22%5D%0A%0A Input: S = %223z4%22%0A Output: %5B%223z4%22, %223Z4%22%5D%0A%0A Input: S = %2212345%22%0A Output: %5B%2212345%22%5D%0A%0A Note:%0A%0A S will be a string with length at most 12.%0A S will consist only of letters or digits.%0A%0A */%0A%0A
 publ
@@ -149,16 +149,18 @@
  _784 %7B%0A
+  
   public
@@ -185,16 +185,20 @@
 tion1 %7B%0A
+    
     publ
@@ -243,24 +243,30 @@
 String S) %7B%0A
+      
       Set%3CSt
@@ -299,24 +299,30 @@
 %3C%3E();%0A      
+   
+   
 result.add(S
@@ -324,16 +324,22 @@
 add(S);%0A
+      
       fo
@@ -375,32 +375,40 @@
  i++) %7B%0A        
+     
+   
 if (Character.is
@@ -426,32 +426,42 @@
 S.charAt(i))) %7B%0A
+          
           Set%3CSt
@@ -487,32 +487,42 @@
 ew HashSet%3C%3E();%0A
+          
           for (S
@@ -540,24 +540,36 @@
 : result) %7B%0A
+            
             
@@ -619,32 +619,46 @@
 %7B%0A              
+     
+         
 StringBuilder sb
@@ -687,32 +687,46 @@
 ;%0A              
+     
+         
 for (int j = 0; 
@@ -747,32 +747,48 @@
                 
+    
+            
 sb.append(word.c
@@ -790,32 +790,46 @@
 ord.charAt(j));%0A
+              
               %7D%0A
@@ -834,32 +834,46 @@
 %7D%0A              
+ 
+             
 sb.append(Charac
@@ -898,32 +898,46 @@
 rd.charAt(i)));%0A
+              
               fo
@@ -972,32 +972,48 @@
 ength(); j++) %7B%0A
+                
                 
@@ -1045,34 +1045,62 @@
 ;%0A              
+           
-%7D%0A
+   %7D%0A              
               ne
@@ -1139,16 +1139,28 @@
         
+           
+ 
 %7D else %7B
@@ -1160,16 +1160,30 @@
  else %7B%0A
+              
         
@@ -1234,32 +1234,46 @@
 ;%0A              
+            
+  
 for (int j = 0; 
@@ -1294,32 +1294,48 @@
                 
+            
+    
 sb.append(word.c
@@ -1351,34 +1351,62 @@
 ;%0A              
+         
-%7D%0A
+     %7D%0A              
               sb
@@ -1459,32 +1459,46 @@
 ;%0A              
+        
+      
 for (int j = i +
@@ -1519,32 +1519,48 @@
 ength(); j++) %7B%0A
+                
                 
@@ -1592,34 +1592,62 @@
 ;%0A              
+     
-%7D%0A
+         %7D%0A              
               ne
@@ -1678,32 +1678,66 @@
 ));%0A            
+    
+        %7D%0A                    
 %7D%0A          %7D%0A  
@@ -1723,35 +1723,32 @@
      %7D%0A         
- %7D%0A
           result
@@ -1733,32 +1733,33 @@
                 
+ 
 result.addAll(ne
@@ -1780,18 +1780,38 @@
     
-%7D%0A
+        %7D%0A     
       
+ 
 %7D%0A
+      
     
@@ -1848,16 +1848,22 @@
 t);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 784