MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / findMinDiff

Method findMinDiff

ChocolateDistributionProblem.java:3–13  ·  view source on GitHub ↗
(ArrayList<Long> a, long n, long m)

Source from the content-addressed store, hash-verified

1class Solution
2{
3 public long findMinDiff (ArrayList<Long> a, long n, long m)
4 {
5 // your code here
6 Collections.sort(a);
7 long minDiff = Long.MAX_VALUE;
8 for(int i=0;i+m-1<n;i++)
9 {
10 minDiff = Math.min(a.get(i+(int)m-1)-a.get(i),minDiff);
11 }
12 return minDiff;
13 }
14}

Callers

nothing calls this directly

Calls 1

sortMethod · 0.80

Tested by

no test coverage detected