Timeline for HackerRank Problem - "Queen's attack II"
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 1, 2019 at 22:41 | comment | added | AJNeufeld | Sorry. Code Review requires “the code be posted by the author or maintainer of the code (...) and that the poster know why the code is written the way it is.” It may not be obvious, but I tried to avoid commenting on u/Alviy’s code, and just concentrated on reviewing your code. If you do not understand “what he was doing as (you’re) not familiar with dictionaries”, you shouldn’t be asking for review of the code on Code Review. You should ask for help elsewhere (but can probably glean useful knowledge from @Setris’s answer post). | |
Nov 30, 2019 at 11:28 | vote | accept | Naveen Dookia | ||
Nov 30, 2019 at 10:19 | comment | added | Naveen Dookia | @AJNeufeld first of all thank you for taking time to review my code. Your answer is very detailed and addressed my question in a way I can understand. - Now you asked why am I subtracting 1 from every index when forming a directory, or why don't I use a set instead. The thing is I didn't understand what he was doing as I'm not familiar with directories. I saw that it ran faster so 'copy pasta' .I haven't formally studied python. I am just having fun with coding in my free time. I was hoping you can explain what he was doing with directories and how to do it better? | |
Nov 30, 2019 at 10:13 | comment | added | Naveen Dookia | @ChatterOne I am aware there are other way to go about this problem and I would have turn to those if this hadn't work. For now I just wanted to know that what I'm doing wrong in my code that it is slower than a code that follows the same algorithm | |
Nov 29, 2019 at 14:43 | comment | added | AJNeufeld | @ChatterOne While you have a point, keep in mind CodeReview is a code reviewing site, not a programming challenge answering, grading or tutoring site. The OP wrote that they “optimized it best to what (they) could ... follows basically the same algorithm... but it still runs about 2x slower”. I wasn’t trying to show them the best algorithm; I was reviewing their code, showing them where they could optimize their code further, leaving basically the same algorithm. | |
Nov 29, 2019 at 11:24 | comment | added | ChatterOne |
I agree with your optimizations for how the code is currently written, but my gut is saying that this can be done in O(1) time. After all, if you have a 100x100 board, the maximum vertical and horizontal reach that you can have is 99 (because the queen cannot attack itself). The same actually goes for the diagonals, if you rotate them. If the queen is on, say, (5, 5) , the maximum reach for diagonals will be (5 - 1) + (100 - 5) . You can check if an obstacle is on a diagonal easily by offsetting y = mx (of course you also have to go the opposite direction)
|
|
Nov 29, 2019 at 5:59 | history | edited | AJNeufeld | CC BY-SA 4.0 |
Added explicit lookup of the `i` variable steps, to further emphasis the inefficiency.
|
Nov 29, 2019 at 5:35 | history | answered | AJNeufeld | CC BY-SA 4.0 |