Data Structures & AlgorithmsHardGATE CS · DSA
Reverse the order of words, collapsing multiple spaces. What is printed?
Reverse the order of words, collapsing multiple spaces. What is printed?
s = " new the is oil "
w = s.split()
print("|" + " ".join(reversed(w)) + "|", len(s.split(" ")))- A. |oil is the new| 14
- B. |oil is the new| 12
- C. |oil is the new| 4
- D. |oil is the new| 13
Correct answer: D. |oil is the new| 13
split() with no argument drops empty strings, but split(" ") keeps an empty string for every extra space. Output: |oil is the new| 13.
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
- You must answer many queries 'sum of A[l..r]' while also updating single elements, on an array of n elements. Which choice gives O(log n)…
- An array of 8 integers holds values 1..7 with exactly one value appearing twice: [6, 5, 7, 4, 3, 2, 1, 1]. Treating i → a[i] as a linked…
- Overlapping versus non-overlapping substring counts. What is printed? python s, p = "aabaabbbabab", "bab" over = sum(1 for i in…
- Rabin–Karp with base 10 and a deliberately small modulus counts true matches and spurious hits (hash equal, text different). What is…
- A fixed window of length 3 slides over s = "baacbbbcbcabab" with a character-count array. At how many starting positions is the window an…
- Keys are inserted into a hash table of size 10 with h(k) = k mod 10 and quadratic probing (h(k) + i²) mod 10. Which statement is correct?