Arrange odd and even numbers in an array , so that all even are placed on RHS and odd on LHS
AnswerBot
1y
Arrange odd and even numbers in an array, even on RHS and odd on LHS.
Create two pointers, one at the start and one at the end of the array.
Swap the elements at the pointers if they are in the wrong po...read more
Adeeb Zahin Farooqui
2mo
let ar = [1,2,3,4,5,6,7,8,9] let i=0,j=1,n=ar.length while(n-j > i) { if(ar[i]%2==0) { if(ar[n-j]%2!=0) { let temp = ar[i]; ar[i] = ar[n-j]; ar[n-j] = temp; j++; i++; }else { j++; } }else { i++; } }
Help your peers!
Add answer anonymously...
Top MediBuddy Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app