Resolve Overlapping Pricing Condition Records Into Effective Price Timeline
Last updated: November 29, 2026
Quick Overview
Pricing condition records arrive in creation order, each with an inclusive valid-from day, valid-to day, and price; a newer record overrides older ones wherever their validity overlaps. Return the effective non-overlapping price segments, merging adjacent segments that end up with the same price.
SAP
November 29, 20260
0
0 solved
Pricing condition records arrive in creation order, each with an inclusive valid-from day, valid-to day, and price; a newer record overrides older ones wherever their validity overlaps. Return the effective non-overlapping price segments, merging adjacent segments that end up with the same price.
SAP onsite coding rounds for Sales and Distribution or pricing engine teams use this because condition records with validity periods are central to how S/4HANA determines a price on a sales order. The interviewer wants a sweep line with a priority structure instead of a day-by-day array, plus care with inclusive bounds.
What the Interviewer Expects
- Converts inclusive validity ranges to half-open intervals to avoid off-by-one errors
- Sweeps over sorted boundary points rather than every calendar day
- Uses a max-heap on creation index with lazy deletion to find the winning record
- Merges adjacent segments that share a price
- Leaves gaps where no record is valid
- Gives O(n log n) complexity
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you answer many point queries (price on day d) without building the full timeline?
- How would you support deleting a condition record after the timeline is built?
- What if records also have a priority (access sequence) that outranks creation order?
- How would you store the result so it is cheap to update when one new record arrives?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Days are integers. Record i covers [from_i, to_i] inclusive. On any day, the record with the largest index (newest) among those valid that day sets the price. Output a sorted list of `(start, end, p...
High-Level Design
The winner can only change at a boundary: a record start, or the day after a record end. Collect those points and sort them. Walk the points in order; at each point push any records that start there o...