dailycodebase

2 month data structures and algorithmic scripting challenge starting from 20th December 2018 - Coding is Fun! πŸ’―πŸ’― Do it everyday!! Also, Do give us a ⭐ if you liked the repository

View on GitHub

cover

Day 49 - MiddleMost Node Search

Given a singly linked list, find it’s middle-most element, without knowing the size of the linked list or using any counter variable.

Example

given linked list: 1 -> 2 -> 3
output: 2

given linked list: 1 -> 2 -> 3 -> 4
output: 2

HINT

πŸ‘‰ Make 2 pointer variables which would iterate over the Linked List, such that in each iteration, first variable moves 1 step forward, and the second pointer variable moves 2 steps forward.

πŸ‘‰ When the second pointer reaches the end, first pointer would reach to the middlemost element

ques

Solution

JavaScript Implementation

Solution

// To Be Added