Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
Sum the largest power of two that divides each element of [12, 40, 7, 24]. What is the total?
- A. 22
- B. 41
- C. 21
- D. 20
Correct answer: C. 21
The largest power of two dividing x is x AND -x: 12 gives 4, 40 gives 8, 7 gives 1, 24 gives 8. The total is 21.
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
- On a 3 by 3 grid, how many unordered pairs of distinct cells share a row or a column?
- What is the length of the longest run of equal consecutive values in [5, 5, 5, 6, 6, 5, 5, 5, 5]?
- How many length-2 substrings of "abbaabab" are either "ab" or "ba"?
- From task sizes [4, 5, 6, 3], what is the largest number of tasks you can keep so that their total size is at most 10?
- How many subsets (including the empty set, but counting each subset once) of [1, 2, 3, 4] have element sum equal to 5?
- Convert (a+b)c/(d-e) to postfix with the shunting-yard algorithm (+ and - lowest, then and /, all left-associative). What is the postfix…