You are not logged in. Please login at to post your questions!


PRIMEDST - long august 13

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.

asked 13 Aug '13, 03:39

code_master01's gravatar image

accept rate: 0%

@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 .


answered 13 Aug '13, 10:12

vineetpaliwal's gravatar image

accept rate: 12%

edited 13 Aug '13, 10:13

@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.


answered 13 Aug '13, 12:17

code_master01's gravatar image

accept rate: 0%

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.

(13 Aug '13, 13:08) boochman5★

yes java supports lesser recursive calls.

(20 Aug '13, 00:32) aichemzee4★

most recursive sol give tle

(20 Aug '13, 01:27) akashverma_1233★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 13 Aug '13, 03:39

question was seen: 854 times

last updated: 20 Aug '13, 01:27