Negative numbers [mp]
Micro pattern¶
Description¶
Handle sign separately or preserve both extremes when negative values reverse arithmetic ordering.
Problems¶
Separate sign from magnitude¶
Perform an operation on magnitudes and restore its signed interpretation.
- 7. Reverse Integer (Top Easy)
- 8. String to Integer (atoi) (Top Easy)
- 29. Divide Two Integers (Top Medium)
- 50. Pow(x, n) (Top Medium)
- 166. Fraction to Recurring Decimal (Top Medium)
- 227. Basic Calculator II (Top Hard)
Reverse an ordering or extremum¶
Account for negative values reversing product size or magnitude order.
- 152. Maximum Product Subarray (Top Hard)
- LSD radix sort (DSA)
Fixed-width signed representation¶
Mask intermediate values and reinterpret the final unsigned pattern.
- 371. Sum of Two Integers (Top Medium)