package com.freetymekiyan.algorithms.level.easy;

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

/**
 * 412. Fizz Buzz
 * <p>
 * Write a program that outputs the string representation of numbers from 1 to n.
 * <p>
 * But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.
 * For numbers which are multiples of both three and five output “FizzBuzz”.
 * <p>
 * Example:
 * <p>
 * n = 15,
 * <p>
 * Return:
 * [
 * "1",
 * "2",
 * "Fizz",
 * "4",
 * "Buzz",
 * "Fizz",
 * "7",
 * "8",
 * "Fizz",
 * "Buzz",
 * "11",
 * "Fizz",
 * "13",
 * "14",
 * "FizzBuzz"
 * ]
 */
public class FizzBuzz {

    private static final String FIZZ = "Fizz";
    private static final String BUZZ = "Buzz";

    public List<String> fizzBuzz(int n) {
        List<String> res = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            StringBuilder builder = new StringBuilder();
            if (i % 3 == 0) {
                builder.append(FIZZ);
            }
            if (i % 5 == 0) {
                builder.append(BUZZ);
            }
            if (builder.length() == 0) {
                builder.append(i);
            }
            res.add(builder.toString());
        }
        return res;
    }
}
@@ -473,20 +473,24 @@
 %0A * 
+%7C
 %5B%0A *
+ %7C 
  %221%22,%0A *
  %222%22
@@ -489,16 +489,19 @@
 ,%0A *
+ %7C 
  %222%22,%0A *
  %22Fi
@@ -492,24 +492,27 @@
 * %7C  %222%22,%0A *
+ %7C 
  %22Fizz%22,%0A * 
@@ -514,16 +514,19 @@
 ,%0A *
+ %7C 
  %224%22,%0A *
  %22Bu
@@ -517,24 +517,27 @@
 * %7C  %224%22,%0A *
+ %7C 
  %22Buzz%22,%0A * 
@@ -531,24 +531,27 @@
   %22Buzz%22,%0A *
+ %7C 
  %22Fizz%22,%0A * 
@@ -553,16 +553,19 @@
 ,%0A *
+ %7C 
  %227%22,%0A *
  %228%22
@@ -564,16 +564,19 @@
 ,%0A *
+ %7C 
  %228%22,%0A *
  %22Fi
@@ -567,24 +567,27 @@
 * %7C  %228%22,%0A *
+ %7C 
  %22Fizz%22,%0A * 
@@ -585,16 +585,19 @@
 izz%22,%0A *
+ %7C 
  %22Buzz%22,
@@ -599,16 +599,19 @@
 uzz%22,%0A *
+ %7C 
  %2211%22,%0A 
@@ -607,24 +607,27 @@
  %7C  %2211%22,%0A *
+ %7C 
  %22Fizz%22,%0A * 
@@ -625,16 +625,19 @@
 izz%22,%0A *
+ %7C 
  %2213%22,%0A 
@@ -637,16 +637,19 @@
 %2213%22,%0A *
+ %7C 
  %2214%22,%0A 
@@ -649,16 +649,19 @@
 %2214%22,%0A *
+ %7C 
  %22FizzBu
@@ -671,10 +671,62 @@
 %0A * 
+%7C
 %5D%0A
+ * %3Cp%3E%0A * Companies: Google, Bloomberg, Apple, IBM%0A
  */%0A
@@ -752,18 +752,16 @@
 zz %7B%0A%0A  
- 
- 
 private 
@@ -797,18 +797,16 @@
 izz%22;%0A  
- 
- 
 private 
@@ -843,18 +843,16 @@
 zz%22;%0A%0A  
- 
- 
 public L
@@ -885,19 +885,21 @@
 ) %7B%0A    
-   
+final
  List%3CSt
@@ -925,28 +925,24 @@
 ayList%3C%3E();%0A
-    
     for (int
@@ -960,30 +960,24 @@
 = n; i++) %7B%0A
-      
       String
@@ -1017,30 +1017,24 @@
 er();%0A      
-  
-    
 if (i %25 3 ==
@@ -1043,32 +1043,24 @@
 ) %7B%0A        
-   
-     
 builder.appe
@@ -1071,38 +1071,26 @@
 IZZ);%0A      
- 
-     %7D%0A      
+%7D%0A
       if (i 
@@ -1105,32 +1105,24 @@
 ) %7B%0A        
- 
-       
 builder.appe
@@ -1131,30 +1131,24 @@
 (BUZZ);%0A
-      
       %7D%0A
         
@@ -1135,30 +1135,24 @@
 Z);%0A      %7D%0A
-      
       if (bu
@@ -1182,24 +1182,16 @@
         
-      
-  
 builder.
@@ -1211,28 +1211,16 @@
     
-      %7D%0A    
+%7D%0A
       
-  
 res.
@@ -1248,26 +1248,18 @@
 ));%0A    
-    %7D%0A    
+%7D%0A
     retu
@@ -1266,15 +1266,13 @@
 rn res;%0A
-  
   %7D%0A%7D

Update 412 FizzBuzz