Skip to content

Commit 9b687eb

Browse files
author
navneet
committed
Added get-maze-path problem and added complexities in previous problems
1 parent e06b9d2 commit 9b687eb

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/_Problems_/get-mazePath/index.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//======================================Problem Statement=============================================
2+
// --->> Print all possible path to reach the end of the GRID/MAZE (N x N) from starting point to ending point
3+
// --->> One horizontal move will be represented by H and one vertical move will be represented by V
4+
// --->> Complexity = Complexity will be exponential as there are many overlapping solutions
5+
// --->> cr = current row
6+
// --->> cc = current column
7+
// --->> er = end row
8+
// --->> ec = end column
9+
10+
11+
12+
13+
let getMazePath = (cr, cc, er, ec) => {
14+
if(cr == er && cc == ec) { //============POSITIVE BASE CASE===========
15+
let br = [];
16+
br.push('');
17+
return br;
18+
}
19+
20+
if(cr > er || cc > ec) { //============NEGATIVE BASE CASE===========
21+
let br = [];
22+
return br;
23+
}
24+
25+
let myResult = [];
26+
27+
let recResultH = getMazePath(cr, cc + 1, er, ec);
28+
recResultH.forEach((rrh) => {
29+
myResult.push("H" + rrh);
30+
});
31+
32+
let recResultV = getMazePath(cr + 1, cc, er, ec);
33+
recResultV.forEach((rrv) => {
34+
myResult.push("V" + rrv);
35+
});
36+
37+
return myResult;
38+
}
39+
40+
41+
let path = getMazePath(0, 0, 2, 2);
42+
console.log(path);

src/_Problems_/getStringPermutation

Whitespace-only changes.

src/_Problems_/get_subsequence/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SUBSTRING OF 'bc' ---->>>> ['', 'b', 'c', 'bc']
44
// SUBSTRING OF 'c' ---->>>> ['', 'c']
55
// A pattern can be noticed in above three substrings. Technique followed is recursion.
6+
// Time complexity : O(2^n) n is the length of the string provided.
67

78

89
let getSubesequence = (str) => {
@@ -25,4 +26,5 @@ let getSubesequence = (str) => {
2526

2627

2728
let subsequence = getSubesequence('abc');
28-
console.log(subsequence);
29+
console.log(subsequence);
30+

0 commit comments

Comments
 (0)