Midpoint of a Linked List — Coding Question

Placewit
2 min readMar 16, 2022

--

Problem Statement:

For a given singly linked list of integers, find and return the node present at the middle of the list

Input format :

The first line contains the elements of the singly linked list separated by a single space.

Remember/Consider :

While specifying the list elements for input, -1 indicates the end of the singly linked list and hence, would never be a list element

Output Format :

For each test case/query, print the data value of the node at the middle of the given list.

Output for every test case will be printed in a seperate line.

Sample Input 1 :

1 2 3 4 5 -1

Sample Output 1 :

3

Sample Input 2 :

1 2 3 4 -1

Sample Output 2 :

2

Code:

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

Placewit
Placewit

Written by Placewit

Upskilling students for tech placements!

No responses yet