Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall

In c++ given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

The overall run time complexity should be O(log (m+n)).

Input

In the first line enter the size of the first array

In the second line enter the list of numbers of the first array

In the third line enter the size of the second array

In the last line enter the list of numbers of the second array

Output

The output is the median of the two sorted arrays

Example of input

2 1 3 1 2 

Example of output

The median is 2 

Constraints:

nums1.length == m

nums2.length == n

0 <= m <= 1000

0 <= n <= 1000

1 <= m + n <= 2000

-106 <= nums1[i], nums2[i] <= 106

GIVEN CODE TO WORK WITH:

#include #include #include

using namespace std;

double findMedianSortedArrays(vector& nums1, vector& nums2) { //********************************* //your code here //*********************************** }

int main(){ vector firstList; vector secondList; int sizeFirstList; int sizeSecondList; int numbersList1; int numbersList2;

//Enter size of vector 1: cin>>sizeFirstList; if(sizeFirstList<0 || sizefirstlist>1000) { cout<<"Try again and enter an integer greater than or equal to 0, and less than or equal to 1000"<> numbersList1; if(numbersList1<-106 || numbersList1>106){ cout<<"Try again and enter an integer greater than or equal to -106, and less than or equal to 106"<

//Enter size of vector 2: cin>>sizeSecondList; if(sizeSecondList<0 || sizesecondlist>1000) { cout<<"Try again and enter an integer greater than or equal to 0, and less than or equal to 1000"<> numbersList2; if(numbersList2<-106 || numbersList2>106){ cout<<"Try again and enter an integer greater than or equal to -106, and less than or equal to 106"<

cout<<"The median is "<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions