HackerRank Day 21 Generics 30 days of code solution YASH PAL, 31 July 202413 October 2025 HackerRank Day 21 Generics solution – In this problem set, we need to write a function printArray that can take an array of generic elements as a parameter and that function can print each element of its generic array parameter on a new line.ObjectiveIn this challenge we will discuss about the Generics. TaskWrite a single generic function named printArray; this function must take an array of generic elements as a parameter (the exception to this is C++, which takes a vector). The locked Solution class in your editor tests your function.Note: You must use generics to solve this challenge. Do not write overloaded functions.Input FormatThe locked Solution class in your editor will pass different types of arrays to your printArray function. ConstraintsYou must have exactly function named printArray.Output FormatYour printArray function should print each element of its generic array parameter on a new line.Generics Problem solution in java.class Printer<E> { //Write your code here public <E> void printArray(E[] array) { for (E element : array) { System.out.println(element); } } }Problem solution in c++./** * Name: printArray * Print each element of the generic vector on a new line. Do not return anything. * @param A generic vector **/ template <class T> void printArray(vector<T> vec){ for(int i=0; i<vec.size(); i++) cout<<vec[i]<<endl; } 30 days of code coding problems solutions HackerRank