Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
Reverse the order of words, collapsing multiple spaces. What is printed?
Reverse the order of words, collapsing multiple spaces. What is printed?
s = " oil is data new "
w = s.split()
print("|" + " ".join(reversed(w)) + "|", len(s.split(" ")))- A. |new data is oil| 4
- B. |new data is oil| 12
- C. |new data is oil| 13
- D. |new data is oil| 15
Correct answer: C. |new data is oil| 13
split() with no argument drops empty strings, but split(" ") keeps an empty string for every extra space. Output: |new data is oil| 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
- Merge two sorted linked lists by relinking nodes (ties take the node from the first list). What is printed? python def merge(a, b): d = t…
- ^ is exponentiation (highest precedence, right-associative); and / come next; + and − are lowest; others are left-associative. What is the…
- Keys 93, 31, 142, 74, 55, 139, 99 are inserted in this order into an empty table of size 11 by double hashing: h1(k) = k mod 11, h2(k) = 5…
- Using a sliding window with a last-seen index map, what is the length of the longest substring of "dbcedadaadcced" with all characters…
- Shell sort with gap sequence 4, 2, 1 (gapped insertion sort for each gap). What is the array after the gap-4 pass only? python a = [20…
- A 2-D array A[0..9][0..19] of 4-byte elements is stored in row-major order starting at address 1000. What is the address of A[7][7]?