Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5578 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 714 |
@Manikanta punnam | 579 |
@sriramgoparaju99 | 532 |
@praveenbgp6 | 525 |
@yashkaril4 | 517 |
@prankursharma31 | 489 |
@rdakka | 467 |
@sonamnigam1999 | 441 |
@purohitmn02 | 427 |
@sonamkumari63928 | 426 |
@shubhamstudent5 | 419 |
Complete Leaderboard |
Given a link list of size N, modify the list such that all the even numbers appear before all the odd numbers in the modified list. The order of appearance of numbers within each segregation should be same as that in the original list.
Example 1:
Input: N = 7 Link List = 17 -> 15 -> 8 -> 9 -> 2 -> 4 -> 6 -> NULL Output: 8 2 4 6 17 15 9 Explaination: 17,15,8,9 are odd so they appear first and 2,4,6 are the even numbers that appear later.
Example 2:
Input: N = 4 Link List = 1 -> 3 -> 5 -> 7 Output: 1 3 5 7 Explaination: There is no even number. So ne need for modification.
Your Task:
You do not need to read input or print anything. Your task is to complete the function divide() which takes N and head of Link List as input parameters and returns the head of modified link list.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 100
1 ≤ arr[i] ≤ 10000
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes