We have a circular doubly linked list with several elements. Every element has a link to the next element, a link to the previous element and a boolean value (true or false). Four operations are defined for this list:
- Get the value of the current element;
- Reverse the value of the current element;
- Move to the next element;
- Move to the previous element;
How to find the number of list elements with such conditions? Is it possible?
The idea was to cast all elements to the same value, except one. Counting elements amount of such a list is not a problem, but how can I find out, that all elements are traversed?
You can do this in O(N) time: