03. Decimal Equivalent of Binary Linked List
The problem can be found at the following link: Question Link
My Approach
I am iterating through the linked list, treating it as a binary representation of a number.
At each step, I shift the current result left by one bit (multiply by 2) and add the current node's data.
I also take care to update the result modulo 1e9 + 7 to avoid overflow.
Time and Auxiliary Space Complexity
Time Complexity :
O(N)
, where N is the number of nodes in the linked list.Auxiliary Space Complexity : O(1)
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.
Last updated