PRIMEDST - long august 13

nzec
primedst

#1

Hello, I kept on getting NZEC on PRIMEDST with my soln

I figured out that it was StackOverflowError, can someone please help and suggest some way to implement the algorithm in space efficient manner.


#2

@code_master01 : StackOverflowError happens when you use recursion and number of times your function is recursing is a little large . It is not necessarily related to space usage . The same code may work perfectly with same space usage if implemented in iterative fashion . I have also experienced StackOverflowError in past for recursive functions and an iterative implementation of same logic has been accepted .


#3

@vineetpaliwal what modifications do u suggest exactly? because i m doing a dfs using recursion, i wonder whether changing it to iterative version (which explicitly uses stack) would be helpful.


#4

You are right, just use stack and it will work. FYI, if you were using c++ you could stick with your recursive dfs, but java has it’s limits.


#5

yes java supports lesser recursive calls.


#6

most recursive sol give tle