Rewrite Task: EXACTLY 3 SKILLS (the original algorithm + file I/O + JSON parsing) in a single cohesive task.
Task Description
Implement a Python program that preserves the original algorithmic requirement while adding file-based JSON input and JSON output. You must provide a function with the same signature and a programmatic entry that reads input from a JSON file and writes output as structured JSON to another file.
Algorithmic requirement (unchanged)
Implement a function find_target_student_height(n: int, students: List[List[int]]) -> int that determines the height of the tallest "target student" in a given 2D list of heights.
A target student is defined as someone who is both the shortest in their row and the tallest in their column.
The function should return the maximum height among all target students. If no target student exists, return 0.
File I/O requirement
Read input from a JSON file located at /app/input.json.
The JSON file contains the fields:
"n": integer, number of rows
"students": a 2D list of integers, where each inner list represents a row of heights (rows may have varying lengths)
JSON parsing and JSON output requirement
Use JSON parsing to read the input and to generate the output.
Write a structured JSON output to /app/output.json with at least the following fields:
"target_height": integer (the result of find_target_student_height)
"target_exists": boolean indicating whether a target student was found (true if target_height > 0, false otherwise)
The program must be self-contained in a single cohesive task (not three separate tasks) and should not rely on external inputs beyond the specified input.json.
Solution Location
Implement the solution in /app/solution.py. The module should define find_target_student_height and include a main block that reads /app/input.json, computes the result, and writes /app/output.json accordingly.
Example
Input (in /app/input.json):
{
"n": 3,
"students": [
[160, 150, 170],
[170, 165, 155],
[180, 175, 160]
]
}
Output (written to /app/output.json):
{
"target_height": 175,
"target_exists": true
}
Notes
If n is 0, or if no valid target exists, target_height should be 0 and target_exists should be false.
Inner rows may have varying lengths; the solution should handle irregular shapes gracefully by considering only existing column indices within each row.