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 tried it! didn't work, solution was timed out.
Question asks for a recursive approach :/
I have to admit, my comment was a slightly dickish comment that this is DP, not memoization.
Sorry for that.
Read again siebenschlaefer's message: he was asking for "between" each call (more than one year ago... when he wasn't 1 kyu yet...). And between them, nothing is stored.
Answer: yes. Dictionaries are slow structures so if you want to access to "regularly ordered" data knowing where the value you need is stored, the list is the better way.
only one call but it does store: with the append. Inside the append, it retrieves via indexing.
If that's not obvious, run it with a print statement in the loop to see the contents of fib change.
Question: is using a list for this faster than a dictionary? Same retrieval cost but don't have to pay for hashing???
This is more of a DP approach than memoization, which the author particular asked for in the prompt.
If doing DP, there is no need for the list data structure. You can just keep 2 variables for n-1 and n-2. This reduces Space complexity to O(1)
This function does not store any results between calls, right?
I can verify. My solution does not produce the correct output for this proposed test case as well because 2/4 is not in its most simplified form, so it computes the lcm for 4, 5 and 7 when it really should be computing the lcm for 2, 5 and 7. Really good observation here--the question should be changed to also require the simplification of fractions, which would be a nice additional exercise.
I agree. Most of the top solutions have this bug, because the tests of this kata do not cover the case that a rational may not be initially simplified.
I opened a suggestion about this here: http://www.codewars.com/kata/54d7660d2daf68c619000d95/discuss
you may test this input: convertFracts([[2,4],[4,5],[6,7]]), your answer is [[70, 140], [112, 140], [120, 140]], the right answer is [[35, 70], [56, 70], [60, 70]]