Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

Q3 solution by Haris Jamal Khan#9

Open
harisjamalkhan111 wants to merge 1 commit into
Kodifly:mainfrom
harisjamalkhan111:patch-3
Open

Q3 solution by Haris Jamal Khan#9
harisjamalkhan111 wants to merge 1 commit into
Kodifly:mainfrom
harisjamalkhan111:patch-3

Conversation

@harisjamalkhan111
Copy link
Copy Markdown

Create a variable count to have a count of elements in the output array. If the value of (m+n) is odd then there is only one median else the median is the average of elements at index (m+n)/2 and ((m+n)/2 – 1). To merge both arrays, keep two indices i and j initially assigned to 0. Compare the ith index of 1st array and jth index of the second, increase the index of the smallest element and increase the count. Store (m+n)/2 and (m+n)/2-1 in two variables.
Check if the count reached (m+n) / 2. If (m+n) is odd return m1, If even return (m1+m2)/2.

Create a variable count to have a count of elements in the output array.
If the value of (m+n) is odd then there is only one median else the median is the average of elements at index (m+n)/2 and ((m+n)/2 – 1).
To merge both arrays, keep two indices i and j initially assigned to 0. Compare the ith index of 1st array and jth index of the second, increase the index of the smallest element and increase the count.
Store (m+n)/2 and (m+n)/2-1 in two variables.
Check if the count reached (m+n) / 2. If (m+n) is odd return m1, If even return (m1+m2)/2.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant