Skip to content

Lesson 2: findStartLoop #62

Description

@seemcat

Takes in a linkedList and returns true if the circular loop starts anywhere in the list.

Example 1: (linkedList starts at n1)

const n1 = { val: 'n1Val', };
const n2 = { val: 'n2Val', };
const n3 = { val: 'n3Val', };

n1['next'] = n2;
n2['next'] = n3;
n3['next'] = n2;

Input: n1
Output: true because the circular loop started somewhere in the list.

Example 2: (linkedList starts at n1)

const n1 = { val: 'n1Val', };
const n2 = { val: 'n2Val', };
const n3 = { val: 'n3Val', };
const n4 = { val: 'n4Val', };

n1['next'] = n2;
n2['next'] = n3;
n3['next'] = n4;
n4['next'] = n2;

Input: n1
Output: true because the circular loop started somewhere in the list.

Example 3: (linkedList starts at n1)

const n1 = { val: 'n1Val', };
const n2 = { val: 'n2Val', };
const n3 = { val: 'n3Val', };

n1['next'] = n2;
n2['next'] = n3;

Input: n1
Output: false because the circular loop does not start somewhere in the list.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions