Data Structures & AlgorithmsHardCodeforces Div2 C · LeetCode-style
Cards with values [4, 1, 7, 3, 9, 2, 5] lie in a row. In each of 3 moves you take the card at the LEFT end or the RIGHT end. What is the maximum total value you can collect?
- A. 16
- B. 11
- C. 18
- D. 21
Correct answer: A. 16
A prefix plus a suffix of total length k: try every split of k into left and right takes, using prefix and suffix sums. Greedily taking the larger visible end at each move can give up a better combination further in.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many ordered sequences of positive integers, each at most 3 and with at least two terms, sum to 6?
- For the array [3, 5, 6, 1], compute the XOR of every non-empty contiguous subarray and add all these XOR values together. What is the total?
- How many non-empty contiguous subarrays of [2, 4, 6, 1, 3, 1, 2, 4] have a bitwise XOR equal to 0?
- What is the length of the shortest contiguous substring of "xaybzcabbc" that contains "abc" as a SUBSEQUENCE (the letters appear in order…
- How many index triples i < j < k in "abacbab" spell a palindrome of length 3, meaning s[i] = s[k]? (The middle letter is unrestricted.)
- What is the smallest integer x ≥ 100 whose binary representation contains exactly 4 ones?