https://leetcode.com/problems/reverse-linked-list-ii/
-
Naively, this requires two passes
- Once to collect data, if the counter passes
leftthen we can begin to store the value of each node in an-array like structure (plain array orstd::vectorboth work) - Once more to populate each node with corresponding data in the array when
leftis passed
- Once to collect data, if the counter passes
-
Structure considerations
vectormay be easier due topush_back()method andend()[-n]which allows us to obtain the last index- array size can be initialised with
right - left,counter - leftinstead ofpush_back, andright - counterto obtain the index when populating