package com.fishercoder.solutions;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * 942. DI String Match
 *
 * Given a string S that only contains "I" (increase) or "D" (decrease), let N = S.length.
 *
 * Return any permutation A of [0, 1, ..., N] such that for all i = 0, ..., N-1:
 *
 * If S[i] == "I", then A[i] < A[i+1]
 * If S[i] == "D", then A[i] > A[i+1]
 *
 * Example 1:
 * Input: "IDID"
 * Output: [0,4,1,3,2]
 *
 * Example 2:
 * Input: "III"
 * Output: [0,1,2,3]
 *
 * Example 3:
 * Input: "DDI"
 * Output: [3,2,0,1]
 *
 * Note:
 * 1 <= S.length <= 10000
 * S only contains characters "I" or "D".
 */
public class _942 {
  public static class Solution1 {
    public int[] diStringMatch(String S) {
      Queue<Integer> deque = new ArrayDeque<>();
      for (int i = 0; i <= S.length(); i++) {
        deque.add(i);
      }
      int[] result = new int[S.length() + 1];
      for (int i = 0; i <= S.length(); i++) {
        if (i == S.length()) {
          result[i] = ((ArrayDeque<Integer>) deque).pollLast();
        } else if (S.charAt(i) == 'I') {
          result[i] = ((ArrayDeque<Integer>) deque).pollFirst();
        } else {
          result[i] = ((ArrayDeque<Integer>) deque).pollLast();
        }
      }
      return result;
    }
  }
}

@@ -87,542 +87,8 @@
 e;%0A%0A
-/**%0A * 942. DI String Match%0A *%0A * Given a string S that only contains %22I%22 (increase) or %22D%22 (decrease), let N = S.length.%0A *%0A * Return any permutation A of %5B0, 1, ..., N%5D such that for all i = 0, ..., N-1:%0A *%0A * If S%5Bi%5D == %22I%22, then A%5Bi%5D %3C A%5Bi+1%5D%0A * If S%5Bi%5D == %22D%22, then A%5Bi%5D %3E A%5Bi+1%5D%0A *%0A * Example 1:%0A * Input: %22IDID%22%0A * Output: %5B0,4,1,3,2%5D%0A *%0A * Example 2:%0A * Input: %22III%22%0A * Output: %5B0,1,2,3%5D%0A *%0A * Example 3:%0A * Input: %22DDI%22%0A * Output: %5B3,2,0,1%5D%0A *%0A * Note:%0A * 1 %3C= S.length %3C= 10000%0A * S only contains characters %22I%22 or %22D%22.%0A */%0A
 publ
@@ -105,16 +105,18 @@
 942 %7B%0A  
+ 
+ 
 public s
@@ -139,16 +139,20 @@
 tion1 %7B%0A
+    
     publ
@@ -182,24 +182,30 @@
 String S) %7B%0A
+      
       Queue%3C
@@ -237,24 +237,30 @@
 yDeque%3C%3E();%0A
+      
       for (i
@@ -301,16 +301,24 @@
         
+    
+    
 deque.ad
@@ -325,26 +325,38 @@
 d(i);%0A      
-%7D%0A
+      %7D%0A      
       int%5B%5D 
@@ -391,24 +391,30 @@
 + 1%5D;%0A      
+    
+  
 for (int i =
@@ -433,32 +433,40 @@
 ength(); i++) %7B%0A
+        
         if (i ==
@@ -482,32 +482,42 @@
 ()) %7B%0A          
+ 
+         
 result%5Bi%5D = ((Ar
@@ -558,24 +558,32 @@
 ();%0A        
+ 
+       
 %7D else if (S
@@ -599,24 +599,34 @@
 ) == 'I') %7B%0A
+          
           re
@@ -682,24 +682,32 @@
 ();%0A        
+   
+     
 %7D else %7B%0A   
@@ -703,16 +703,26 @@
  else %7B%0A
+          
         
@@ -789,24 +789,44 @@
     
+      
-%7D%0A      %7D%0A
+  %7D%0A            %7D%0A  
       
+    
 retu
@@ -840,16 +840,22 @@
 lt;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 942