Midpoint of a Linked List — Coding Question

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.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Create a PR to merge a fork’s changes using Github CLI

Conscripts Upgraded

Decorator Design Pattern in ASP.NET Core

The first rule simply enforces your code to conform to the rules of hooks that I’ve explained

Reflection on This Past 3 Months

Journey to Automated Permissions Management

How we wrote xtensor 2/N: access operators

Decide which startup deserves best pitch honors and a top prize worth $1M at Microsoft Build 2019

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Reverse a Queue Coding Question

One interview, Many learnings

K Smallest Elements

Running Median — Coding Question