Created
          December 7, 2020 17:17 
        
      - 
      
- 
        Save iJustErikk/fefd115cfefac1101f623aed7e9790f2 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const gridTraveler = (m, n) => { | |
| // create 2 dimensional array | |
| const grid = new Array(m + 1) | |
| .fill().map(() => new Array(n + 1).fill(0)); | |
| grid[1][1] = 1; | |
| for (let i = 0; i < m + 1; i += 1) { | |
| for (let j = 0; j < n + 1; j += 1) { | |
| // add current value to right and down if possible | |
| const currentValue = grid[i][j]; | |
| if (i < m) grid[i + 1][j] += currentValue; | |
| if (j < n) grid[i][j+1] += currentValue; | |
| } | |
| } | |
| return grid[m][n]; | |
| }; | |
| console.log(gridTraveler(20, 20)); | |
| console.log(gridTraveler(3,3)); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment