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



I'm getting WA can anyone tell me what I'm doing wrong or the test case which fails in this.

asked 21 Jan '13, 13:39

cyberghost23's gravatar image

accept rate: 0%

converted to question 21 Jan '13, 14:14

anton_lunyov's gravatar image

6★anton_lunyov ♦

Try this test:

0 4 2 12
2 1 9 24
0 1 9 12
2 8 2 18
The answer is 2.
While your answer is 12.

The answer is 12.
While your answer is 2.


answered 21 Jan '13, 14:07

anton_lunyov's gravatar image

6★anton_lunyov ♦
accept rate: 12%

edited 25 Jan '13, 16:44

Hi Anton, Is (1,1) connected to (1,4)? I don't seem to understand the connectivity rules to get to answer 2. Thank you for the small test case. -nnovoice

(25 Jan '13, 08:49) nnovoice2★

Hi Anton, I was checking this link: and you have posted the same test case with 12 as the answer! -nnovoice

(25 Jan '13, 09:06) nnovoice2★

Sorry, I've swapped the correct and yours answers :P
Is this clear your doubt?

(25 Jan '13, 14:35) anton_lunyov ♦6★

Thank you. BTW, that was not my answer! -nnovoice

(25 Jan '13, 16:39) nnovoice2★

Hi Anton, Would you be able to help me in finding why my solution fails with SIGSEGV: If you could help me with a test case, I will try to find out. I have tried to find a problem in the code without success. Thank you. -nnovoice

(14 Feb '13, 17:48) nnovoice2★

The reason is stack overflow in DFS.
Try to get rid of arrays rows[] and cols[].
For example, you could make them vectors.
Then they will be allocated not in stack.

(15 Feb '13, 02:07) anton_lunyov ♦6★

Thank you Anton! I will try that.

(15 Feb '13, 06:36) nnovoice2★

I tried vector<int> but they slowed down the execution. So, I went with allocating memory on the heap using new. Submitted with correct answer! Thank you!

(15 Feb '13, 09:44) nnovoice2★
showing 5 of 8 show all

@cyberghost23 : In your submission , you are using Arrays.binarySearch() . However the length of the array of primes "p" is not exactly the number of primes till the range you have found them . You should store the number of primes which are valid entries in array of primes "p" . And then you should use the method Arrays.binarySearch(int [] array , int fromIndex , int endIndex , int value ) . Pass fromIndex = 0 and endIndex = number of valid prime entries in the array . If you do binary search on the whole array , there are some junk entries in the end of array , which make the results undefined as the array now may not be sorted due to junk entries and binary search will not be able to function properly .


answered 16 Feb '13, 12:26

vineetpaliwal's gravatar image

accept rate: 12%

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: 21 Jan '13, 13:39

question was seen: 1,026 times

last updated: 07 Mar '17, 16:47