What up replers!
I've got an algorithms problem for you, where you're trying to find the longest pay it forward chain of gifts.
Check the details there👆 - and comment down if you have any questions.
The first to get a solution that works (only js please!) gets a $5 bitcoin prize - include your BTC address with your solution.
Edit: @ammarbinfaisal won 🏆
you want something like this https://repl.it/@ammarbinfaisal/r-g-hist-chain-challenge ??
It returns all the chains that have the max chain length. The chains are inverted though, i.e. the last person is at index 0 and the first person is at index n.
Two questions :
- Do you just need the chain length or do you need the nodes of each chain?
- If history JSON is real time data that is stored from read.gift is it okay to assume that the data is already chronologically ordered?
are we doing your homework or something?
your json is invalid because you need quotes for the keys
also there are some strange data points where the buyer is the same as the receiver and also this one where the receiver is just
anyways, the instructions were a little hard to understand. I hope I interpreted the "pay it forward chain" correctly and here is my solution:
if i got it backwards it should be easy to fix
@MrEconomical oof that was a stupid mistake, added quotes.
by pay it forward chain, I mean where person B is gifted a book by Person A, and then gifts a book to person C, after which Person C gifts a book to Person D and so on.
In this case, the chain would be
A => B => C => D.
One person can appear multiple times in a chain.