Histogram index out of bounds
Review this Go helper that returns the absolute value of a 32-bit ADC reading, used to index a histogram.
Readings come from a signed 16.16 fixed-point ADC and are stored as int32, including occasional rail-to-rail values.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1func absInt32(x int32) int32 {
2 if x < 0 {
3 return -x
4 }
5 return x
6}
7
8func record(hist []uint64, reading int32) {
9 idx := absInt32(reading)
10 hist[idx]++ // hist is sized to the max expected magnitude
11}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.