Data Structures & AlgorithmsModerateWipro · Accenture pattern
What is printed? (anagram check two ways)
What is printed? (anagram check two ways)
from collections import Counter x, y = "listen", "enlists" print(sorted(x) == sorted(y), Counter(x) == Counter(y), set(x) == set(y))
- A. True True True
- B. False True True
- C. False False False
- D. False False True
Correct answer: D. False False True
"enlists" has an extra 's', so sorted letters and counts differ – not anagrams. A set comparison ignores multiplicity and wrongly says True. Sorting is O(n log n); counting is O(n).
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
- Binary search: how many iterations does this loop run to find x = 23? python a = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] lo, hi, it = 0…
- What is printed? (run-length decode then re-encode) python import re enc = "a3b1c12" dec = "".join(ch int(n) for ch, n in…
- What is printed? (move zeros to the end keeping order) python a = [0, 1, 0, 3, 12, 0, 5] w = 0 for r in range(len(a)): if a[r] != 0: a[w]…
- What is the time complexity of deleting the last node of a singly linked list of n nodes when only a head pointer is kept?
- A stack is implemented with a singly linked list. Where should push and pop operate to keep both O(1)?
- What is printed? (C strings) c char s[] = "Placement"; printf("%zu %zu", strlen(s), sizeof(s));