Ask coding questions

← Back to all posts
A challenge with a $5 bitcoin prize
jajoosam (829)

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 🏆

Have fun!

Answered by ammarbinfaisal (9) [earned 5 cycles]
View Answer
jajoosam (829)

@ammarbinfaisal Yes, perfect! What's your bitcoin address?

ammarbinfaisal (9)

@jajoosam ugh don't have one... and you don't need to do that :)

jajoosam (829)

@ammarbinfaisal I appreciate the help :)

If you ever create a page, hmu and I'll gift you a book!

HackermonDev (1987)

Oof I missed the challenge

RajivReddy (0)

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.

RajivReddy (0)

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 is it okay to assume that the data is already chronologically ordered?
jajoosam (829)


  • Need the nodes of each chain
  • Yes, ok to assume data is already chronologically ordered

are we doing your homework or something?

theangryepicbanana (1691)

I'd do this but why only js lol


@theangryepicbanana yeah js is boring

jajoosam (829)

@theangryepicbanana iss gotta go in the nodejs codebase for

MrEconomical (2274)

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 true

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

jajoosam (829)

@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.

AdCharity (1357)

@MrEconomical nice altough I don't really have a clue what he's talking about