Python Forum
Where is the loophole in my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where is the loophole in my code
#11
(Jan-24-2017, 06:34 PM)micseydel Wrote: (I deleted a solution that someone provided that may have been doing the OP's homework for them.)

Ah, but this ain't "Homework". Shouldn't the thread be moved to "Homework" then?
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#12
It was clearly homework from the OP, where it says "You must do this in-place without making a copy of the array. / Minimize the total number of operations." Shoulda been moved sooner.
Reply
#13
What do you mean homework from OP?
I am not a student. I am learning Python by myself. I am practicing by coding those questions from online challenges.
This is a question from Leetcode.

My codes passed all the test cases, except this strange one. I have know idea why it failed on last "0". I really want to find out this.
Reply
#14
OP = original post.
Too many students say they're not students, so we have to assume it, please don't take it personally :)
(Even if it's on Leetcode, someone could have assigned it.)

As for the failure - as mentioned, your code is inefficient. It's quadratic where linear solutions are possible (some of us have been PMing them for fun, and someone else posted a spoiler that was deleted). This may be why it's failing, if you're confident that the logic is correct. It looks fine to me.

If you don't know what I'm talking about, try start here and if you still have questions feel free to post them on this thread and we'll help you optimize your solution.
Reply
#15
Thanks for the suggestions on efficiency matters. I will spend some time focusing on efficiency stuff.
I realized there are better ways to do this. I just curious about what is wrong by this stupid way, even I know it is slow, but the logic seems right.
Anyway, maybe I should give up on this question and save time for moving on new challenges and readings
Reply
#16
(Jan-27-2017, 12:49 AM)landlord1984 Wrote: Anyway, maybe I should give up on this question and save time for moving on new challenges and readings
That's very possible. Efficiency is an advanced topic, and has enough math that it might be worth developing more programming experience before trying to tackle it. It's definitely worth learning at some point, but I was programming for ~5 years without any issues before learning it. It can be very fun once you do learn it though, and the basics of efficiency only require arithmetic. Advanced efficiency topics, such as analyzing recursive functions, can require inductive proofs which are a more advanced kind of math.

In any case, whichever way you choose will probably be fine :)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020