package com.fishercoder.solutions;

/**
 * 62. Unique Paths

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach
the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?
 */
public class _62 {

  public static class Solution1 {
    /**
     * Another typical DP question, use a 2d array: the first row and the first column need to be
     * initialized to be 1 since there's only one way to reach every position in the first row and
     * the first column: either from left or top.
     */
    public int uniquePaths(int m, int n) {
      int[][] dp = new int[m][n];
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
          if (i == 0 || j == 0) {
            dp[i][j] = 1;
          } else {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
          }
        }
      }
      return dp[m - 1][n - 1];
    }
  }
}

@@ -33,349 +33,8 @@
 s;%0A%0A
-/**%0A * 62. Unique Paths%0A%0AA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).%0AThe robot can only move either down or right at any point in time. The robot is trying to reach%0Athe bottom-right corner of the grid (marked 'Finish' in the diagram below).%0A%0AHow many possible unique paths are there?%0A */%0A
 publ
@@ -48,17 +48,18 @@
 s _62 %7B%0A
-%0A
+  
   public
@@ -84,16 +84,20 @@
 tion1 %7B%0A
+    
     /**%0A
@@ -101,16 +101,20 @@
 **%0A     
+   
+ 
 * Anothe
@@ -203,16 +203,20 @@
 be%0A     
+   
+ 
 * initia
@@ -306,16 +306,20 @@
 nd%0A     
+   
+ 
 * the fi
@@ -364,15 +364,23 @@
     
+    
 */%0A    
+  
+  
 publ
@@ -410,24 +410,30 @@
 m, int n) %7B%0A
+      
       int%5B%5D%5B
@@ -454,16 +454,22 @@
 %5Bm%5D%5Bn%5D;%0A
+      
       fo
@@ -496,32 +496,40 @@
  i++) %7B%0A        
+ 
+       
 for (int j = 0; 
@@ -552,16 +552,26 @@
         
+        
+  
 if (i ==
@@ -582,24 +582,36 @@
 %7C j == 0) %7B%0A
+            
             
@@ -638,17 +638,39 @@
     
-%7D else %7B%0A
+          %7D else %7B%0A            
     
@@ -731,28 +731,58 @@
     
+       
-%7D%0A        %7D%0A      %7D%0A
+   %7D%0A                %7D%0A            %7D%0A      
     
@@ -812,16 +812,22 @@
 1%5D;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 62