Skip to content

Instantly share code, notes, and snippets.

@victoraguilarc
Created May 21, 2025 12:05
Show Gist options
  • Save victoraguilarc/8f266cdc9c47ed2cad10cabd3a83a924 to your computer and use it in GitHub Desktop.
Save victoraguilarc/8f266cdc9c47ed2cad10cabd3a83a924 to your computer and use it in GitHub Desktop.
Code Challenge
"""
The Challenge
We have a small file with employees, their manager IDs, and the LLM‑scored responses from the last week. We need to be able to answer the following questions:
What’s each person’s average engagement score?
Which employees are currently at risk (average < ‑0.25)?
What’s the chain of command for any at‑risk person?
The input
A csv file with the following columns. week_scores is a list of integers representing the scores for each week.
employee_id,manager_id,week_scores
1,,1,1,0
2,1,1,0,-1
3,1,1,1,1
4,2,-1,-1,0
5,2,0,-1,-1
6,3,1,0,1
7,4,0,-1,-1
The objective
Write a class that reads and stores the data from the CSV file in an adequate data structure so:
We can calculate the average score based on the employee id.
We can identify the employee at risk (average < -0.25).
Identify the chain of command of an employee at risk.
"""
collection = [
[1, None, 1, 1, 0],
[2, 1, 1, 0,-1],
[3, 1, 1, 1,1],
[4, 2, -1,-1,0],
[5, 2, 0,-1,-1],
[6, 3, 1,0,1],
[7, 4, 0,-1,-1],
]
employees = {}
for item in collection:
employee_id = item[0]
manager_id = item[1]
week_scores = item[2:]
score_average = sum(week_scores) / len(week_scores)
employees[employee_id] = {
"employee_id": employee_id,
"manager_id": manager_id,
"score": score_average,
"risk": score_average < -0.25
}
def get_chain_of_command(employees: dict, employee_id: int) -> list[int]:
employee = employees.get(employee_id, {})
manager_id = employee.get("manager_id")
if employee and manager_id is not None:
return get_chain_of_command(employees, manager_id) + [employee_id]
return [employee_id]
for employee_id, employee in employees.items():
if employee["risk"]:
print(f"\nRisky: employee_id={employee_id} score={employee['score']} ")
print(f"Chain of Command: {get_chain_of_command(employees, employee_id)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment