DSA #5
DSA GRIND #5 - ASHUR BAROUTTA
This week I chose to touch back on a linkedlist problem as I find that to be an interesting data structure. I think the problem is cool, it states
"Given head, the head of a linked list, determine if the linked list has a cycle in it.
There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to."
So the problem is asking us to traverse the linked list in a specific way to see if there is a cycle. At first I thought this problem wouldn't take me much time but it ended up being alot more challenging than going from node to node and checking what was next.
I ended up using two different pointers to traverse the list at different "speeds". Was proud of this one. The results are okay in terms of rank, but im starting to move away from putting much stock in the rankings and more value in approach to the solution.
The solution is below :
Nice work, Ashur!
ReplyDelete