Exercise: Solve this problem in Go. Write code and test cases too. https://github.com/one2nc/student-grading-go (We use this problem statement as an offline exercise during our hiring process. From the bootcamp point of view, you don’t need to send us your solution, solve this exercise and self-evaluate your code with feedback given below)
Labels: Beginner
Time to complete: 1 day
What will you learn: Go basics, CSV parsing, struct basics, for loop, map, slices, file reading
Instructions:
- Don’t use any third-party CSV parsing library. Read the file line by line and parse each CSV line into a Student struct.
- Perform only basic validation checks on the CSV. Assume that the input data in CSV will be valid and correct (in terms of data types and actual values too)
How to evaluate your solution:
- All the test cases should pass.
- Implement stringer method for Student struct (to print a student object using
fmt.Println
) (not related to the problem, but nice to have)
- Are you closing the CSV file correctly after use? Have you used the
defer
block correctly?
- Are you reusing
findOverallTopper
method fromfindTopperPerUniversity
method? Since we are grouping students by the university, we can usefindOverallTopper
method from insidefindTopperPerUniversity
method.
- You should be using a
map[string]studentStat
in the findTopperPerUniversity method.
- Ensure method names should be verbs.
- Method names or variable names should be smaller (Go convention)
- We should not mention datatype in variable naming (no need for
strName
variable name)
- Any function should return value instead of printing on the console as much as possible (minimise the side-effects)
- To deal with errors in Go, return a (value, error) from the function (handle or declare rule)
- As much as possible, left indent your code. (avoid
else
block)
- When dealing with collections as return types (array, slice, maps), write test cases for 0, 1 and many values.
Actual Solution:
- Don’t look at the solution unless you have you. Otherwise, you’re not getting much value from the bootcamp.
I know what I am doing, stop patronising me
If you say so 🤷, here’s the sample implementation:
Student-grading-go SolutionÂ