Data Structures & AlgorithmsVery hardTCS Digital · Infosys SP
Only the lower triangle (including the diagonal) of a 10 × 10 matrix is stored COLUMN by column in a 1-D array B starting at B[0] (indices 0-based). At which index of B is element (7, 5) stored?
- A. 52
- B. 43
- C. 42
- D. 33
Correct answer: C. 42
Column k of the lower triangle holds n − k elements (rows k..n − 1). Columns 0..4 hold 40 elements; element (7, 5) is 2 further down column 5: index 42.
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 keeps a second stack of running minimums. What is printed? python st, mn, out = [], [], [] for op in [8, "pop", 8, 8, "pop"…
- Reverse a singly linked list in groups of k (a final group shorter than k is left as it is). What is printed? python def revk(h, k): cnt…
- Print a matrix in spiral order (right, down, left, up, repeat). What is printed? python m = [[50, 81, 32, 23], [30, 61, 32, 23], [60, 51…
- A chained hash table stores n = 2,000 keys in m = 500 buckets with simple uniform hashing. What is the expected number of key comparisons…
- Bars of width 1 have heights [5, 5, 7, 8, 6, 5, 2, 8]. What is the area of the largest rectangle that fits under the histogram (computed…
- Product of all elements except self, using prefix and suffix products (no division). What is printed? python a = [2, 3, 3, 2, -1] n =…