Median of 2 sorted arrays

preview_player
Показать описание
This video explains a very important programming interview problem which is to find the median of 2 sorted arrays. We will proceed through the solution ideas from most basic approach to the most optimal approach.

----------------------------------------------------------------------------------------------------------------------------------------------------------------
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Рекомендации по теме
Комментарии
Автор

🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037

techdoseu
Автор

this is best explanation for this problem, thanks!!

ganeshchandrasaladi
Автор

class Solution {
public:
double nums1, vector<int>& nums2) {
int m = nums1.size(), n = nums2.size();
int totalSize = m + n;
int medianPos1 = (totalSize - 1) / 2, medianPos2 = totalSize / 2;

int i = 0, j = 0, count = 0;
int current = 0, prev = 0;

while (count <= medianPos2) {
prev = current;
if (i < m && (j >= n || nums1[i] <= nums2[j])) {
current = nums1[i++];
} else {
current = nums2[j++];
}
count++;
}

if (totalSize % 2 == 0)
return (prev + current) / 2.0;
else
return current;
}
};

atharvakulkarni
Автор

Thanks for this video! Amazing explanation 🔥

priyathamv
Автор

Is it me only who is having trouble understanding the optimized approach??

ThedijkstraAlgo