Trains the technique from
LeetCode 653Two Sum IV - Input is a BSTThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A cold store files its calibration cards in a branching index. Every card carries one signed offset in tenths of a degree, and no two cards carry the same offset. Each card holds at most two cards below it, one on its low side and one on its high side, and the filing rule holds everywhere: every offset filed anywhere below a card on its low side is smaller than that card's offset, and every offset filed anywhere below it on its high side is larger.
The index reaches you as index, a band listing, one band of the index at a time from the top down and left to right within a band. Slot 0 holds the topmost card. Each card that appears in the listing takes the next two unclaimed slots for what hangs below it, the low side first and the high side second. A slot holding null means nothing hangs there, and such a slot claims no slots of its own. Trailing null slots are left off the end of the listing.
Return true when the index holds two different cards whose offsets add up to k, and false otherwise. One card cannot be counted twice, so an offset that is exactly half of k is no use on its own.
Example 1
The card carrying 6 and the card carrying 14 are two different cards and their offsets come to 20.
Example 2
The two largest offsets in the index are 13 and 14, which come to 27, so no pair of cards reaches 100.
Example 3
There is only one card. Its offset is half of 8, but a single card cannot be counted twice.
Example 4
The card carrying -3 and the card carrying 3 are different cards and their offsets cancel out.
Example 5
The index has two cards, and 2 with 5 comes to 7.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_target(index: list[int | None], k: int) -> bool:public boolean findTarget(Integer[] index, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.