Given the head of a singly linked list, determine if the list contains a loop, where a loop exists if a node’s next pointer points back to a previous node, creating a circular structure; otherwise, the list ends with a null pointer.
The input includes the linked list and a 1-based position (pos) indicating the node to which the last node connects, forming a loop (if pos = 0, there is no loop). Return true if a loop is detected, otherwise return false.
Topics
Companies
Articles
Examples:
Expected Time Complexity: O(n)
Expected Space Complexity: O(1)
Constraints:
1 <= number of nodes <= 10^4
1 <= node->data <= 10^3
Companies:
AmazonSamsungAdobeQualcommPaytm
Topics:
Linked List
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.