N mice and M cheese packets are positioned in a horizontal straight line. You are given the coordinates of the N mice and the M cheese packets in the array mice and the array cheese respectively. Given that a mouse can only eat at most one cheese packet and a particular cheese packet can be eaten by only one mouse. Your task is to find the minimum time it will take for the mice to eat all the cheese packets. Note that mice run at a speed of unit length per second and it takes negligible time for a mouse to eat cheese.
Example 1:
Input:
N = 3, M = 2
mice[] = {1, 3, 6}
cheese[] = {2, 4}
Output:
1
Explanation:
If mice[0] eats cheese[0] and mice[1]
eats cheese[1], then the time taken
will be 1 which is the minimum time
possible.
Example 2:
Input:
N = 3, M = 3
mice[] = {1, 3, 5}
cheese[] = {1, 3, 5}
Output:
0
Explanation:
For every cheese packet, one mouse is
present at its position. Therefore, the
minimum time taken is 0 in this case
Your Task:
Complete the function minTimeToEat() which takes the integers N, M and the arrays mice and cheese as the input parameters, and returns the minimum time it takes to eat all the cheese packets.
Constraints:
1 ≤ M ≤ N ≤ 103
1 ≤ mice[i], cheese[i] ≤ 109Can Anyone help me in this question or Any similar question on leetcoe