Sum Signed Values in Java with IntStream
Combine absolute values and matching boolean signs with IntStream. Check cancellation, all-negative input, int bounds, and the equal-length array contract.
Practical notes on Java, Spring, testing, and software engineering, with working examples and source references.
Combine absolute values and matching boolean signs with IntStream. Check cancellation, all-negative input, int bounds, and the equal-length array contract.
Build n values from x through x*n with IntStream. Explain why mapToLong alone does not prevent int overflow, and check positive, negative, and zero steps.
Reduce adjacent equal-character pairs with a stack. Explain the prefix invariant, cascading removal, million-character boundaries, and time and space costs.
Subtract completion counts from participant counts with HashMap. Handle duplicate names without Set subtraction and explain the one-missing-runner contract.
Count stopped and reached players, sort exact rates with long cross-products, and handle unreachable stages, full completion, and stage-number tie-breaking.
Count distinct types with HashSet and prove the selection bound is achievable. Distinguish the maximum type count from constructing an actual selection.
Implement ID normalization with an Optional chain and a loop. Check dot collapsing, empty input after filtering, truncation cleanup, padding, and locale independence.
Multiply matching array elements and sum them with IntStream. Understand signs, int bounds, and why wider multiplication must promote operands before overflow.
Normalize valid mixtures of digits and zero-to-nine words using literal replacement. Distinguish replace from replaceAll and explain integer bounds and scope.
Simulate an LRU cache with access-ordered LinkedHashMap. Check hit refresh, eviction, case-insensitive keys, zero capacity, and the model’s cost assumptions.