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...
MediBuddy Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter