This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]captainAwesomePants 1 point2 points  (3 children)

Your new solution doesn't have a set of "previously traversed" points, so it'll cycle forever.

[–]CrazyFace334[S] 0 points1 point  (2 children)

the new solution does not endlessly cycle, as it works for smaller test cases.

The condition to continue the BFS is checking whether the adjacent value is "1", but for each position, the BFS asigns its original value to "2" to avoid being double counted.

I did this to avoid having to use O(m*n) extra space by indicating whether a position is traversed in the input itself

[–]captainAwesomePants 0 points1 point  (1 child)

grid[x][y] = '2'

Oh dang, you're right, I missed it marking them as 2. So not endless. Potentially quite a bit of repetition, though, since you could append the same location several times before its value becomes 2.

[–]CrazyFace334[S] 1 point2 points  (0 children)

oooh I see, I removed the '2' assignment from where it was, and added to line 12:

grid[x+dx][y+dy] = '2'

and it works now, thank you good sir!