Trains the technique from
LeetCode 3287Find the Maximum Sequence Value of ArrayThis 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 rack holds punch cards in a row, codes[i] being the code punched on the i-th card. Every code is below 128.
Take exactly 2 * pick cards off the rack, keeping the rack's order. The first pick cards you took go on the left tray and the last pick on the right tray.
The reading of such a choice is the bitwise OR of the left tray's codes, XOR the bitwise OR of the right tray's codes. Return the largest reading you can get.
Example 1
All four cards are taken, so the left tray ORs to 3 and the right tray to 12. Those share no bits, so the reading is 15.
Example 2
Putting a card punched 127 on one tray and a card punched 1 on the other leaves every bit set but the lowest, which is 126. No choice does better, since both trays would have to differ in all seven bits.
Example 3
Skipping the third card puts 8 and 1 on the left tray for 9 and 4 and 2 on the right for 6, and 9 XOR 6 is 15. Taking four cards side by side never reaches that.
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 max_value(codes: list[int], pick: int) -> int:public int maxValue(int[] codes, int pick)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.