educative.io

Which will be a better solution here? , using an arrayList which is dynamic in nature or first calculating the the number of odd numbers and then create an array of that size

Which will be a better solution here? , using an ArrayList which is dynamic in nature or first calculating the the number of odd numbers and then create an array of that size, because just to get the number of odd numbers calculation looks overhead. I just want something which is dynamic in size

Time complexity to remove the even numbers is O(N) in both array and list. But if there’s a case where we have a huge input then array is faster as compared to list.