Given an array of integers, rearrange the elements such that all odd numbers are placed on the left-hand side (LHS) and all even numbers are placed on the right-hand side (RHS).

AnswerBot
2y

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
9mo
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!
Select
Add answer anonymously...

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. How do you check if a number is an integer?
A Software Engineer was asked Q2. Given a sorted array nums, remove the duplicates in-place such that each element...read more
A Software Engineer was asked Q3. How would you evaluate a BODMAS expression?
MediBuddy Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits