Skip to content

Commit

Permalink
#24 Step towards fixing the TLE error
Browse files Browse the repository at this point in the history
Still need to fix other two test cases
  • Loading branch information
debojyoti-majumder authored May 30, 2019
1 parent 248adcd commit 668dccc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions 2019Q1/cppWorkspace/leetcode576.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class Solution {
return possiblePaths;

auto toLeft{currentPos};
toLeft.x--;
toLeft.y--;

auto toRight{currentPos};
toRight.x++;
toRight.y++;

auto toUp{currentPos};
toUp.y--;
toUp.x--;

auto toDown{currentPos};
toDown.y++;
toDown.x++;

// Adding all the posibilities
possiblePaths.emplace_back(toLeft);
Expand All @@ -60,8 +60,7 @@ class Solution {
}

public:
int findPaths(int m, int n, int N, int i, int j)
{
int findPaths(int m, int n, int N, int i, int j) {
auto retCount{0};
_boundary.first = m;
_boundary.second = n;
Expand All @@ -82,12 +81,17 @@ class Solution {
_visitedMatrix[currentPos.x][currentPos.y] = true;

// Get all the possible coordidate in which the in next move
currentPos.movesLeft--;
auto paths{getPossiblePaths(currentPos)};
auto nextMove { currentPos };
nextMove.movesLeft--;
auto paths{getPossiblePaths(nextMove)};

for (const auto &p : paths) {
if (isOutside(p)) {
retCount += 1;
if( currentPos.movesLeft > 2 )
retCount += 2;
else
retCount += 1;

retCount = retCount % (int)(pow(10,9) + 7);
}
else if( _visitedMatrix[p.x][p.y] == false ) {
Expand Down

0 comments on commit 668dccc

Please sign in to comment.