Skip to content

Instantly share code, notes, and snippets.

@PreciousNyasulu
Created February 9, 2023 07:18
Show Gist options
  • Save PreciousNyasulu/6e13ebd4fdaad290c1a7af22f04764b2 to your computer and use it in GitHub Desktop.
Save PreciousNyasulu/6e13ebd4fdaad290c1a7af22f04764b2 to your computer and use it in GitHub Desktop.
Problem #2
using System;
class Program
{
static int MaxPumpPower(int[] fields, int[] waterTowers)
{
Array.Sort(fields);
Array.Sort(waterTowers);
int i = 0, j = 0, maxDistance = 0;
while (i < fields.Length && j < waterTowers.Length)
{
if (fields[i] <= waterTowers[j])
{
maxDistance = Math.Max(maxDistance, waterTowers[j] - fields[i]);
i++;
}
else
{
j++;
}
}
return maxDistance;
}
static void Main(string[] args)
{
int[] fields = { 1, 5};
int[] waterTowers = {10 };
Console.WriteLine(MaxPumpPower(fields, waterTowers));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment