-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23d1fa2
commit ae57b9a
Showing
1 changed file
with
10 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
Difficulty: Hard/Median of 2 Sorted Arrays of Different Sizes/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h2><a href="https://www.geeksforgeeks.org/problems/median-of-2-sorted-arrays-of-different-sizes/1">Median of 2 Sorted Arrays of Different Sizes</a></h2><h3>Difficulty Level : Difficulty: Hard</h3><hr><div class="problems_problem_content__Xm_eO"><p><span style="font-size: 14pt;">Given two sorted arrays <strong>a</strong> and <strong>b</strong> of size <strong>m</strong> and<strong> n</strong> respectively. You need to find and return the <strong>median </strong>of the two sorted arrays.</span></p> | ||
<p><span style="font-size: 14pt;">Note: Assume that the two sorted arrays are merged and then median is selected from the combined array.</span></p> | ||
<p><span style="font-size: 14pt;"><strong>Examples:</strong></span></p> | ||
<pre><span style="font-size: 14pt;"><strong>Input: </strong>a[] = [1, 5, 9], b[] = [2, 3, 6, 7] | ||
<strong>Output: </strong>5<strong> | ||
Explanation: </strong>If we merge the arrays and sort them then it will become<strong> </strong>[1, 2, 3, 5, 6, 7, 9]<strong style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;"> </strong><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;">The middle element for [1, 2, 3, 5, 6, 7, 9] is 5</span></span></pre> | ||
<pre><strong style="font-family: 'andale mono', monospace; font-size: 14pt;">Input: </strong><span style="font-family: 'andale mono', monospace; font-size: 14pt;">a[] = [4, 6], b[] = [1, 2, 3, 5]<br></span><span style="font-size: 14pt; font-family: 'andale mono', monospace;"><strong>Output: </strong>3.5<br><strong>Explanation: </strong>If we merge the arrays and sort them then it will become<strong> </strong>[1, 2, 3, 4, 5, 6]. Since the arrays size of now even, hence the median is the average of the two middle elements.<br>The two middle elements here are 3 and 4 hence the median is (3+4)/2 = 3.5</span></pre> | ||
<pre><span style="font-size: 14pt; font-family: 'andale mono', monospace;"><span style="font-size: 14pt;"><strong>Input: </strong>a[] = [4], b[] = [1, 2] | ||
<strong>Output: </strong>2<br><strong>Explanation: </strong>If we merge the arrays then it will become<strong> </strong>[1, 2, 4]. The median of the resultant array is the middle element after sorting it. Hence the answer is 2.<br></span></span></pre> | ||
<p><span style="font-size: 14pt;"><strong>Constraints: </strong><br>1 ≤ a.size(), b.size() ≤ 10<sup>6</sup><br>1 ≤ a[i], b[i] ≤ 10<sup>9</sup></span></p></div><p><span style=font-size:18px><strong>Company Tags : </strong><br><code>Amazon</code> <code>Microsoft</code> <code>Samsung</code> <code>Google</code> <br><p><span style=font-size:18px><strong>Topic Tags : </strong><br><code>Arrays</code> <code>Searching</code> <code>Data Structures</code> <code>Algorithms</code> |