Showing invalid argument error

https://ide.codingblocks.com/s/151510 This is my code and its showing error for getNodeAt function

Hey @tanjuljain19,
I have commented the error on line 221. https://ide.codingblocks.com/s/151608
You need to decrement right instead of incrementing.

But this code will still give you error for the input type:
4
2 4 6 8
Do a dry run for this input and understand where you are going wrong.

Could not figure out the error associated with the input you suggsted

Hi @tanjuljain19,
You need to put an additional condition on your while loop.

	while (ln.data % 2 != 0 && left<this.size) {
			
			ln = getNodeAt(left);
			left++;
		}
		while (rn.data % 2 == 0 && right>=0) {
			
			rn = getNodeAt(right);
			right--; //you will decrement right instead of incrementing
		}

Else you will get error for inputs like:
4
2 4 6 8
or
4
1 3 5 7

Still getting one test case wrong… Sir, Why did you put ln=getNodeAt(left) Statement before the left++ statement. I think in that case each node will be visited twice

Hello @tanjuljain19,
https://ide.codingblocks.com/s/153064 I have modified your code a little.
In this question the order of the odd and even numbers should be the way they are given.
For example:
Input:
5
1 2 3 4 5
Output:
1 3 5 2 4
We cannot output 1 5 3 2 4 or any other permutations.

So in the approach I gave you, we have divided the array in 2 parts. Odd and even.

When the data is even, it is appended in the even linked list and if it is odd, it is appended in the off linked list.

After that, we insert a condition to prevent errors in case all elements are even or all elements are odd.

Then we simply join the 2 linked list in the order given in the question. (Left elements followed by the even elements)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.