Data Structures & AlgorithmsHard
How many index pairs i < j in 2 3 4 6 8 12 9 satisfy A[i]·A[j] = 24?
- A. 2
- B. 0
- C. 3
- D. 6
Correct answer: C. 3
Each unordered index pair is tested once, so the product target 24 is matched by factor pairs present in the array. Using the wrong target, adding instead of multiplying, or doubling for order gives different totals.
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
- A min-stack stores a pair (value, current minimum) per entry. Why does popping never require recomputing the minimum?
- In the 'remove nodes with a greater value to their right' problem, which list order is processed to decide survivors in O(n)?
- In the asteroid collision problem, why does a stack of right-moving asteroids suffice?
- A linear-time check decides whether a permutation can be sorted by one stack. Which property is equivalent to being stack-sortable?
- In the jump game (minimum number of jumps), why does a single left-to-right scan with a 'current boundary' count the jumps correctly?
- In the 'first non-repeating character in a stream' problem, why is a queue with lazy removal used?