We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7390539 commit 732db44Copy full SHA for 732db44
1 file changed
Company_OA/Amazon_SDE_2025/Approach.md
@@ -0,0 +1,18 @@
1
+### Approach
2
+
3
+We use two pointers: left and right to simulate buying books from both ends.
4
5
+- If pairCost is cheaper than buying both ends separately, and we still have k pair discounts left, we use it.
6
+- Otherwise, we buy the cheaper of the two ends individually.
7
+- If only one book remains, we buy it directly.
8
9
+### Edge Cases
10
+- If k = 0, we never use the pair option.
11
+- If pairCost >= cost[left] + cost[right], it's better to buy individually.
12
13
+### Tips
14
+- Always compare pairCost with cost[left] + cost[right].
15
+- Use long to avoid overflow for large cost arrays.
16
17
+### Time Complexity
18
+- **O(n)** – We process each book once.
0 commit comments