Java Program to Store Even & Odd Elements of an Array into Separate Arrays
Given an array with N numbers and separate those numbers into two arrays by odd numbers or even numbers. The complete operation required O(n) time complexity in the best case. For optimizing the memory uses, the first traverse through an array and calculate the total number of even and odd numbers in it. Create two arrays with size calculated after traversing and start storing them.
Below is the implementation of the above approach:
Even Array contains: 54 76 66 2 Even Array contains: 23 55 9 91
Time Complexity: O(n)
Space Complexity: O(n)
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.