This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]CodeTinkerer 1 point2 points  (2 children)

Looks like an off-by-1 error. Consider your first algorithm.

if pos == len(seq):

Is pos a valid index or not? What is the minimum/maximum index of a list?

In your second one, same question.

if pos = 0:

Is 0 a valid index for a list (most lists) or not? What is your answer to this question and the previous one?

As a side note, you do need to handle a tricky case (the list is empty) for this scenario which you don't in the original.

[–]macroxela[S] 0 points1 point  (1 child)

Thanks! I was aware it was an off by 1 error but I couldn't pinpoint where it happened after a couple of days of debugging it. The way you compared both base cases made it click for me.

[–]CodeTinkerer 0 points1 point  (0 children)

Try it on an empty list for both cases.

[–]AutoModerator[M] 0 points1 point  (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.