Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 433 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

Given a singly linked list with **N** nodes and a number **X**. The task is to find the node at the given index (X)(1 based index) of linked list.

**Input:**

First line of input contains number of testcases T. For each testcase, first line of input contains space seperated two integers, length of linked list and X.

**Output:**

For each testcase, there will be single line of output containing data at Xth node.

**User Task:**

The task is to complete the function **GetNth**() which takes head reference and index as arguments and should return the data at Xth position in the linked list.

**Constraints:**

1 <= T <= 30

1 <= N <= 100

K <= N

1 <= value <= 10^{3}

**Example:
Input:**

2

6 5

1 2 3 4 657 76

10 2

8 7 10 8 6 1 20 91 21 2

**Output:**

657

7

**Explanation:
Testcase 1: **Element at 5th index in the linked list is 657 (1-based indexing).

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Node at a given index in linked list

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.