Skip to content

Instantly share code, notes, and snippets.

@KartikTalwar
Created July 2, 2012 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KartikTalwar/3035757 to your computer and use it in GitHub Desktop.
Save KartikTalwar/3035757 to your computer and use it in GitHub Desktop.
K-th Largest Number From 2 Sorted Arrays
<?php
// 2 Arrays $a[m] and $b[n]
$i = 0;
$j = 0;
$p = 0;
$k = 2;
for($p = 1; $p < $k; $p++)
{
if( $a[$i] < $b[$j] )
{
$i = $i + 1;
}
else
{
$j = $j + 1;
}
}
if( $a[$i] < $b[$j] )
{
return $a[$i];
}
else
{
return $b[$j];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment