Skip to content

Commit

Permalink
Create README - GfG to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
kasmeen123 committed Nov 23, 2024
1 parent 23d1fa2 commit ae57b9a
Showing 1 changed file with 10 additions and 0 deletions.
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:&nbsp;</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>&nbsp;<code>Microsoft</code>&nbsp;<code>Samsung</code>&nbsp;<code>Google</code>&nbsp;<br><p><span style=font-size:18px><strong>Topic Tags : </strong><br><code>Arrays</code>&nbsp;<code>Searching</code>&nbsp;<code>Data Structures</code>&nbsp;<code>Algorithms</code>&nbsp;

0 comments on commit ae57b9a

Please sign in to comment.