Data Structures & AlgorithmsHardInfosys · Accenture pattern
For [2, 3, 0, 4], out[i] is the product of all elements except a[i], computed with prefix and suffix products (no division). What is out?
- A. [0, 0, 0, 0]
- B. [0, 0, 24, 0]
- C. [12, 8, 24, 6]
- D. [0, 0, 24, 6]
Correct answer: B. [0, 0, 24, 0]
Only the position of the single zero gets a non-zero product: 2·3·4 = 24. Every other position includes the 0 → 0. The division trick (total / a[i]) fails here because the total is 0 and 0/0 is undefined; [12, 8, 24, 6] is what you get by ignoring the zero.
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
- The intervals [1, 4], [6, 8], [2, 3], [8, 10], [12, 13] are sorted by start and merged (intervals that touch at an endpoint also merge)…
- A 'leader' is an element strictly greater than every element to its right (the last element is always a leader). Scanning from the right…
- The words stop, pots, opts, post, tops, spot, pot, top are grouped so that anagrams share a group (key = the sorted letters). How many…
- A stack is built from two queues with a costly push: enqueue x into the empty queue Q2, move every element of Q1 into Q2 one by one, then…
- With at most k = 2 character replacements, what is the length of the longest substring of 'AABCABBB' that can be turned into a single…
- What is the length of the longest contiguous subarray of [0, 1, 1, 0, 1, 1, 1, 0, 0, 0] with an equal number of 0s and 1s? (Map 0 to −1…