package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * 937. Reorder Log Files
 *
 * You have an array of logs.  Each log is a space delimited string of words.
 *
 * For each log, the first word in each log is an alphanumeric identifier.  Then, either:
 *
 * Each word after the identifier will consist only of lowercase letters, or;
 * Each word after the identifier will consist only of digits.
 * We will call these two varieties of logs letter-logs and digit-logs.  It is guaranteed that each log has at least one word after its identifier.
 *
 * Reorder the logs so that all of the letter-logs come before any digit-log.
 * The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties.
 * The digit-logs should be put in their original order.
 *
 * Return the final order of the logs.
 *
 * Example 1:
 *
 * Input: ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]
 * Output: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]
 *
 * Note:
 * 0 <= logs.length <= 100
 * 3 <= logs[i].length <= 100
 * logs[i] is guaranteed to have an identifier, and a word after the identifier.
 */
public class _937 {
  public static class Solution1 {
    public String[] reorderLogFiles(String[] logs) {
      TreeMap<String, String> letterLogMap = new TreeMap<>();
      List<String> digitLogList = new ArrayList<>();
      for (String log : logs) {
        int firstSpaceIndex = log.indexOf(' ');
        String id = log.substring(0, firstSpaceIndex);
        if (Character.isAlphabetic(log.charAt(firstSpaceIndex + 1))) {
          String key = log.substring(firstSpaceIndex + 1) + id;
          letterLogMap.put(key, log);
        } else {
          digitLogList.add(log);
        }
      }
      String[] reorderedLogs = new String[logs.length];
      int i = 0;
      for (String key : letterLogMap.keySet()) {
        reorderedLogs[i++] = letterLogMap.get(key);
      }
      for (String log : digitLogList) {
        reorderedLogs[i++] = log;
      }
      return reorderedLogs;
    }
  }
}

@@ -111,1129 +111,8 @@
 p;%0A%0A
-/**%0A * 937. Reorder Log Files%0A *%0A * You have an array of logs.  Each log is a space delimited string of words.%0A *%0A * For each log, the first word in each log is an alphanumeric identifier.  Then, either:%0A *%0A * Each word after the identifier will consist only of lowercase letters, or;%0A * Each word after the identifier will consist only of digits.%0A * We will call these two varieties of logs letter-logs and digit-logs.  It is guaranteed that each log has at least one word after its identifier.%0A *%0A * Reorder the logs so that all of the letter-logs come before any digit-log.%0A * The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties.%0A * The digit-logs should be put in their original order.%0A *%0A * Return the final order of the logs.%0A *%0A * Example 1:%0A *%0A * Input: %5B%22a1 9 2 3 1%22,%22g1 act car%22,%22zo4 4 7%22,%22ab1 off key dog%22,%22a8 act zoo%22%5D%0A * Output: %5B%22g1 act car%22,%22a8 act zoo%22,%22ab1 off key dog%22,%22a1 9 2 3 1%22,%22zo4 4 7%22%5D%0A *%0A * Note:%0A * 0 %3C= logs.length %3C= 100%0A * 3 %3C= logs%5Bi%5D.length %3C= 100%0A * logs%5Bi%5D is guaranteed to have an identifier, and a word after the identifier.%0A */%0A
 publ
@@ -127,16 +127,18 @@
  _937 %7B%0A
+  
   public
@@ -163,24 +163,28 @@
 tion1 %7B%0A    
+  
+  
 public Strin
@@ -216,24 +216,30 @@
 g%5B%5D logs) %7B%0A
+      
       TreeMa
@@ -294,16 +294,22 @@
 ;%0A      
+  
+    
 List%3CStr
@@ -343,24 +343,30 @@
 ayList%3C%3E();%0A
+      
       for (S
@@ -377,32 +377,40 @@
 g log : logs) %7B%0A
+        
         int firs
@@ -445,24 +445,32 @@
 ');%0A        
+  
+      
 String id = 
@@ -512,16 +512,24 @@
         
+    
+    
 if (Char
@@ -589,24 +589,34 @@
 %7B%0A          
+      
+    
 String key =
@@ -667,16 +667,26 @@
         
+      
+    
 letterLo
@@ -701,24 +701,32 @@
 (key, log);%0A
+        
         %7D el
@@ -740,16 +740,26 @@
         
+        
+  
 digitLog
@@ -769,24 +769,32 @@
 t.add(log);%0A
+        
         %7D%0A  
@@ -797,24 +797,36 @@
 %7D%0A      
+ 
-%7D%0A
+     %7D%0A    
       
+  
 String%5B%5D
@@ -867,16 +867,22 @@
 ength%5D;%0A
+      
       in
@@ -892,24 +892,30 @@
  = 0;%0A      
+  
+    
 for (String 
@@ -945,32 +945,40 @@
 et()) %7B%0A        
+      
+  
 reorderedLogs%5Bi+
@@ -1011,24 +1011,36 @@
 ;%0A      
-%7D%0A
+      %7D%0A  
       
+    
 for (Str
@@ -1065,32 +1065,40 @@
 List) %7B%0A        
+      
+  
 reorderedLogs%5Bi+
@@ -1113,24 +1113,36 @@
 ;%0A      
-%7D%0A
+      %7D%0A  
       
+    
 return r
@@ -1159,16 +1159,22 @@
 gs;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 937