From 2cb4c2fff4f8826b0ade0c43cfc20ec71ff5f8dd Mon Sep 17 00:00:00 2001 From: Siddhant Swarup Mallick <78552027+siddhant2002@users.noreply.github.com> Date: Sat, 19 Feb 2022 17:29:14 +0530 Subject: [PATCH] Add unique paths (fixes #2873) (#2943) Co-authored-by: Andrii Siriak --- .../dynamicprogramming/UniquePaths.java | 67 +++++++++++++++++++ .../others/UniquePathsTests.java | 56 ++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java create mode 100644 src/test/java/com/thealgorithms/others/UniquePathsTests.java diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java b/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java new file mode 100644 index 00000000..508227f0 --- /dev/null +++ b/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java @@ -0,0 +1,67 @@ +/** Author : Siddhant Swarup Mallick + * Github : https://github.com/siddhant2002 + */ + + +/** + * 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? + */ + +/** Program description - To find the number of unique paths possible */ + +package com.thealgorithms.dynamicprogramming; + +import java.util.*; + +public class UniquePaths { + public static boolean uniquePaths(int m , int n , int ans) { + int []dp = new int[n]; + Arrays.fill(dp,1); + for (int i=1; i