+ 17
unexpected value in array
I have written the following code. Description of the question is given in the code, I am unable to find what is going wrong but it is saving 2 values at. same position. Please help me correct this code. Thanks https://code.sololearn.com/cM54OaWbm3uk/?ref=app
6 Answers
+ 4
So a couple of things:
1. Whenever you are trying to swap values, you need to save the value that you are overwriting. For example: Given 1, 3, 4, 2 as input. When you get to position 2 that has a 3 in it, you replace the 4 in position 3 with 2. So now you have 1, 3, 2, 2.
2 is in pos 3, so 3 will be placed in pos 2:
1, 3, 2, 2
2 is in pos 4, so 4 will be placed in pos 2:
1, 4, 2, 2
2. Givin is spelled given
+ 17
thanks Zeke Williams and ~ swim ~ đ€đ€
+ 15
I will do it by both methods
+ 14
yeah thanks for pointing that out ~ swim ~ I will correct it but even if we input 1,4,3,2 then also it is not giving correct output.
+ 14
please check it for this (1,4,3,2) input. thanks
+ 2
Night_fury~ you're welcome! And ~ swim ~ mentioned another solution; you could just create a separate output 'array' too