Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This is not necessary here cause integers are inmutable on Python, you can't change integers but only change references to new ones wich only would take effect on the list you are doing so, that is only necessary when you are working with mutable objects.
This comment is hidden because it contains spoiler information about the solution
The reasoning and intent of the answer is expressed exactly in the way the code is written.
This comment is hidden because it contains spoiler information about the solution
This kata is a exact problem in the stacks chapter of https://runestone.academy/ns/books/published/pythonds3/index.html. I also used this kata to memorize the book's stack class implementation.
This comment is hidden because it contains spoiler information about the solution
You're right. This solution iterates over the list twice so it's O(n^2). There is a solution in O(n) time.
This is because the difference between two consecutive perfect squares is always odd. If you have a number n, then n+1 squared is: (n+1)^2 = n^2+2n+1. If you subtract n^2, our original number, you get n^2+2n+1-n^2 = (n^2-n^2)+ 2n + 1 = 2n+1. Any number of the form 2n+1 is odd, so the difference must always be an odd number.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution