package com.fishercoder.solutions;

/**
 * 806. Number of Lines To Write String

 We are to write the letters of a given string S, from left to right into lines.
 Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it is written on the next line.
 We are given an array widths, an array where widths[0] is the width of 'a', widths[1] is the width of 'b', ..., and widths[25] is the width of 'z'.

 Now answer two questions:
 how many lines have at least one character from S,
 and what is the width used by the last such line?
 Return your answer as an integer list of length 2.

 Example :
 Input:
 widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
 S = "abcdefghijklmnopqrstuvwxyz"
 Output: [3, 60]
 Explanation:
 All letters have the same length of 10. To write all 26 letters,
 we need two full lines and one line with 60 units.

 Example :
 Input:
 widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
 S = "bbbcccdddaaa"
 Output: [2, 4]
 Explanation:
 All letters except 'a' have the same length of 10, and
 "bbbcccdddaa" will cover 9 * 10 + 2 * 4 = 98 units.
 For the last 'a', it is written on the second line because
 there is only 2 units left in the first line.
 So the answer is 2 lines, plus 4 units in the second line.

 Note:
 The length of S will be in the range [1, 1000].
 S will only contain lowercase letters.
 widths is an array of length 26.
 widths[i] will be in the range of [2, 10].

 */
public class _806 {
  public static class Solution1 {
    public int[] numberOfLines(int[] widths, String S) {
      int numOfLines = 1;
      int offsetInCurrentLine = 0;
      for (char c : S.toCharArray()) {
        if (offsetInCurrentLine + widths[c - 'a'] < 100) {
          offsetInCurrentLine += widths[c - 'a'];
        } else if (offsetInCurrentLine + widths[c - 'a'] == 100) {
          numOfLines++;
          offsetInCurrentLine = 0;
        } else {
          numOfLines++;
          offsetInCurrentLine = widths[c - 'a'];
        }
      }
      return new int[] {numOfLines, offsetInCurrentLine};
    }
  }
}

@@ -33,1579 +33,68 @@
 s;%0A%0A
-/**%0A * 806. Number of Lines To Write String%0A%0A We are to write the letters of a given string S, from left to right into lines.%0A Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it is written on the next line.%0A We are given an array widths, an array where widths%5B0%5D is the width of 'a', widths%5B1%5D is the width of 'b', ..., and widths%5B25%5D is the width of 'z'.%0A%0A Now answer two questions:%0A how many lines have at least one character from S,%0A and what is the width used by the last such line?%0A Return your answer as an integer list of length 2.%0A%0A Example :%0A Input:%0A widths = %5B10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10%5D%0A S = %22abcdefghijklmnopqrstuvwxyz%22%0A Output: %5B3, 60%5D%0A Explanation:%0A All letters have the same length of 10. To write all 26 letters,%0A we need two full lines and one line with 60 units.%0A%0A Example :%0A Input:%0A widths = %5B4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10%5D%0A S = %22bbbcccdddaaa%22%0A Output: %5B2, 4%5D%0A Explanation:%0A All letters except 'a' have the same length of 10, and%0A %22bbbcccdddaa%22 will cover 9 * 10 + 2 * 4 = 98 units.%0A For the last 'a', it is written on the second line because%0A there is only 2 units left in the first line.%0A So the answer is 2 lines, plus 4 units in the second line.%0A%0A Note:%0A The length of S will be in the range %5B1, 1000%5D.%0A S will only contain lowercase letters.%0A widths is an array of length 26.%0A widths%5Bi%5D will be in the range of %5B2, 10%5D.%0A%0A */%0Apublic class _806 %7B%0A  public static class Solution1 %7B%0A
+public class _806 %7B%0A    public static class Solution1 %7B%0A    
     
@@ -148,24 +148,30 @@
  S) %7B%0A      
+     
+ 
 int numOfLin
@@ -178,16 +178,22 @@
 es = 1;%0A
+      
       in
@@ -225,16 +225,22 @@
 ;%0A      
+     
+ 
 for (cha
@@ -260,24 +260,32 @@
 rArray()) %7B%0A
+        
         if (
@@ -333,32 +333,42 @@
 00) %7B%0A          
+    
+      
 offsetInCurrentL
@@ -395,24 +395,32 @@
 '%5D;%0A        
+       
+ 
 %7D else if (o
@@ -458,32 +458,42 @@
  'a'%5D == 100) %7B%0A
+          
           numOfL
@@ -502,32 +502,42 @@
 es++;%0A          
+  
+        
 offsetInCurrentL
@@ -549,24 +549,32 @@
  0;%0A        
+    
+    
 %7D else %7B%0A   
@@ -572,32 +572,42 @@
 lse %7B%0A          
+         
+ 
 numOfLines++;%0A  
@@ -596,32 +596,42 @@
   numOfLines++;%0A
+          
           offset
@@ -671,24 +671,32 @@
         
+  
+      
 %7D%0A      
 %7D%0A      
@@ -687,24 +687,30 @@
 %7D%0A      
+ 
+     
 %7D%0A      
 return n
@@ -701,16 +701,22 @@
 %7D%0A      
+ 
+     
 return n
@@ -723,17 +723,16 @@
 ew int%5B%5D
- 
 %7BnumOfLi
@@ -762,16 +762,22 @@
 e%7D;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 806