using System.Collections.Generic;
public int Id { get; set; }
public string EmpName { get; set; }
public decimal Stats { get; set; }
private static List<Employee> CreateData()
var employee = new List<Employee>();
public static void Main()
var groupList = list.GroupBy(t => t.Id);
var testLinq = (from l in list
let part1 = grp.Count()/2
let part2 = (int)Math.Ceiling((double)grp.Count()/2)
let firstSet = grp.Select(i=>i.Stats).Take(part2)
let secondSet = grp.Select(i=>i.Stats).Skip(part1).Take(part2)
EmpName = grp.FirstOrDefault().EmpName,
Stats = (firstSet.Max() - firstSet.Min()) + (secondSet.Max() - secondSet.Min())
foreach(var row in testLinq){
Console.WriteLine(row.Id);
Console.WriteLine(row.EmpName);
Console.WriteLine(row.Stats);
var finalList = new List<Employee>();
foreach(var grp in groupList){
int part1 = grp.Count()/2,
part2 = (int)Math.Ceiling((double)grp.Count()/2);
var firstSet = grp.Select(i=>i.Stats).Take(part2);
var secondSet = grp.Select(i=>i.Stats).Skip(part1).Take(part2);
var total = (firstSet.Max() - firstSet.Min()) + (secondSet.Max() - secondSet.Min());
finalList.Add(new Employee{
EmpName = grp.FirstOrDefault().EmpName,
foreach(var row in finalList){
Console.WriteLine(row.Id);
Console.WriteLine(row.EmpName);
Console.WriteLine(row.Stats);