C++20 sections · 1024 units
Open in Course

Lessons from Stones

What we learned

You learned adjacent comparison. Check consecutive elements by looping to n2n-2 and accessing arr[i] and arr[i+1]. This pattern appears in finding duplicates, checking sorted sequences, counting runs.

You also saw how to transform a removal problem into a counting problem. Instead of simulating removals, you counted violations. This abstraction simplifies the code and improves performance.

The boundary awareness matters. Off-by-one errors are common when accessing array elements. Always ask: what's the last valid index I can safely access given my current operation?