Data Structures & AlgorithmsEasyTCS NQT · Infosys pattern
What is printed? (Python)
What is printed? (Python)
a = [3, 8, 1, 9, 4] a.insert(2, 7) a.pop() a.remove(9) print(a, len(a))
- A. [3, 8, 7, 1, 4] 5
- B. [3, 7, 8, 1] 4
- C. [3, 8, 7, 1] 4
- D. [3, 8, 1, 7] 4
Correct answer: C. [3, 8, 7, 1] 4
insert(2, 7) puts 7 at index 2: [3, 8, 7, 1, 9, 4]; pop() removes the last element (4); remove(9) deletes the first 9 by value. Result [3, 8, 7, 1], length 4. insert and remove are O(n) because elements shift.
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 circular queue of size N = 5 keeps one slot empty. What is printed (dequeued values, 'F' for each rejected enqueue, final count)? c…
- Keys 50, 700, 76, 85, 92, 73, 101 are inserted into a hash table of size 7 with h(k) = k mod 7 and linear probing. What is the final table…
- Keys 22, 33, 44, 55 go into a table of size 11 with quadratic probing h(k) + i² (mod 11). In which slots do they land, in order? python m…
- What is printed? (stack-based reversal of words) python s = "data structures are fun" st = [] for w in s.split(): st.append(w) out = []…
- Convert the infix expression to postfix (^ is right-associative, higher than and /, which are higher than + and −). What is printed?…
- Evaluate the postfix expression with single-digit operands. What is printed? python st = [] for t in "62/3-42+": if t.isdigit()…