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.
I have completely the same solution!
You actually managed to make shorter version...
You have a list of 2 numbers: [0, abs(res)].
If the (res<0) returns True then the second item is taken. That is because True is the same as 1 in Python and the item with index 1 is abs(res).
If the (res<0) return False then the first item is taken (False = 0 in Python). So the item with index 0 is 0 in that case
This is O(log(n)) solution using binary search
omg, I also thought about dp but came up with simpler solution.
Nice one btw
This kata can be solved without applying special formulas from Numberphile video. It is just for educational purposes. Try to come up with something "easier"
Thank you!
Changed the name of the function to camelCase
Wow, so clever idea, but it runs out of time when
const bound = 1e9 + 1
:(I think I should make tests more separate. For example, divide them into
Random tests with large A values (A <= 10^9)
andRandom tests with small A values (A <= 10^6)
. Also, add more false cases to theExample tests
.Thank you for this information
Thank you, hobovsky, for your long comment!
I made the changes for all languages and now
Incorrect answer for a=x
is printed whenever test is failed. It took me a while to implement this feature for C++ but it was worth it.Cool, you used the optimised strategy :)
Yes, providing three languages at once is boring :/
I am confused. So I should provide the information like
A = 3
(printing the inputs when test is failed)???Loading more items...