ASCI Logo
ASCI.Academy
LearnPracticeCompeteCareer
Sign InGet Started

Search ASCI Academy

Universal search across Courses, Lessons, Skills, Projects, Challenges, Competitions, Jobs, Internships, and Users

dsa intermediate

Curriculum Index

Current LevelInitiate
0/ 500 XP
Gravit Certificate:
100% Required
  • 1.1 Reversing a Singly Linked List
•
1
2
3
4
5
6
7
8
9
10
Module 1: Singly & Doubly Linked Lists•Lesson 1

1.1 Reversing a Singly Linked List

### Pointer Reversal
Keep track of three pointers: prev, curr, and next_temp. At each node, redirect curr.next = prev.

example.pyPython 3.11
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
Python 3.11
•
Interactive Challenge
+85 XP
Challenge Objective

Reverse the 3-node list and print the new head value 'NEW_HEAD: 3'.

solution.py
UTF-84 SpacesAuto-saved
cpython3.11:~/workspace
CPython 3.11.8 (WASM)
$python3 -u solution.py
Click "Compile & Run" (or press Ctrl + Enter) to compile AST, verify bytecode, and execute the solution.