My solution code is along the following lines but it fails on test 4 for wrong answer. Can someone explain what's wrong with this logic/code?
Create a Directed Acyclic Graph by creating edges from a vertex to all the next possible vertices (based on the previous jump length).
Now find the vertex with maximum distance from source vertex. Since it's a DAG, do topological sort and find the longest path in a DAG. Here weight(u,v) is number of gems on vertex v(island v).