public: int kthElement(int arr1[], int arr2[], int n, int m, int k) { int ans[m+n]; for(int i =0;i<n;i++) ans[i]=arr1[i]; int j=0,l=n; while(j<m and l<m+n) { ans[l]=arr2[j]; l++;j++; } //cout<<ans[4]; sort(ans,ans+n+m); return ans[k-1]; }};
Standard input is empty
public: int kthElement(int arr1[], int arr2[], int n, int m, int k) { int ans[m+n]; for(int i =0;i<n;i++) ans[i]=arr1[i]; int j=0,l=n; while(j<m and l<m+n) { ans[l]=arr2[j]; l++;j++; } //cout<<ans[4]; sort(ans,ans+n+m); return ans[k-1]; } };
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!