Рет қаралды 4,461
Source Code: thecodingsimpl...
Solution:
Take a boolean variable flag
Now, iterate from 1st node of list & check if element is less than next element
Same way, in next iteration check if it's greater than next element
In both condition, if condition matches, swap the values
At last, we'll have arranged value
Time Complexity: O(n) for iterating the n elements of linked list
Space Complexity: O(1) as we're taking only constant variables
Please check video for more info:
This problem is similar to:
how to do rearrange a linked list in zig zag manner,
arrange a linked list in zig zag manner,
linked list in zig zag manner,
linked list,
zig zag,
zig-zag,
arrange,
tutorial,
coding simplified,
java
CHECK OUT CODING SIMPLIFIED
/ codingsimplified
I started my KZbin channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 300+ videos. My account is Partner Verified.
★☆★ VIEW THE BLOG POST: ★☆★
thecodingsimpli...
★☆★ SUBSCRIBE TO ME ON KZbin: ★☆★
www.youtube.co...
★☆★ SEND EMAIL At: ★☆★
Email: thecodingsimplified@gmail.com