https://leetcode.com/problems/reverse-linked-list-ii/description/?envType=study-plan-v2&envId=top-interview-150

def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]:
	if not head: return None
	
	# move curr to the right until it is one node prior the first node
	# of the list to reverse
	prev, curr = None, head
	while left > 1:
	    prev = curr
	    curr = curr.next
	    left -= 1
	    right -= 1
	
	# `connection` will be the right most node of the left sublist
	# `tail` will be the right most node of the REVERSED sublist 
	con, tail = prev, curr
	
	# reverse nodes for the length of the sublist
	while right:
	    next_node = curr.next
	    curr.next = prev
	    prev = curr
	    curr = next_node
	    right -= 1
	
	# if a connection exists AKA left does not equal 0 in the problem
	# AKA there is a left sublist, then connect the connection node 
	# (right most node of the left sublist) with the node that is now
	# the beginning node of the REVERSED sublist.
	if con:
	    con.next = prev
	else:
	    head = prev
	    
	# Connect the tail node (right most node of the REVERSED sublist) with 
	# the leftmost node of the right sublist
	tail.next = curr
	return head

$Time = O(N)$

$Space = O(1)$