Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: What is printed? print(f"{3.14159:.2f}", f"{42:05d}", f"{0.5:.0%}")
- A. 3.14 00042 0.5
- B. 3.14 00042 50%
- C. 3.14 42 50%
- D. 3.1 00042 50%
Correct answer: B. 3.14 00042 50%
Format specifiers: .2f rounds to two decimals, 05d pads with zeros to width 5, and .0% multiplies by 100 before formatting. Padding with spaces instead of zeros gives a different result.
More Coding Interview Problems questions
- Problem: In Python, what is the value of (−5 >> 1) + 10, where >> is the arithmetic right shift applied to the negative integer −5?
- Problem: Records (name, score) are sorted by score descending with Python's stable sort…
- Problem: A deque holds 1, 2, 3, 4, 5 from left to right. The operation rotate(2) moves the last 2 elements to the front (rotate right by…
- Problem: A 2D prefix-sum table is built for the grid [[1,2,3],[4,5,6],[7,8,9]]. What is the sum of the submatrix with rows 1–2 and columns…
- Problem: A sparse-table-free query: over the array [5, 2, 8, 1, 9, 3, 7], what is the minimum value on the range of indices [2, 5]…
- Problem: A Fenwick tree (binary indexed tree) over positions 1–8 starts with all zeros. The operations are: add 5 at position 3, add 4 at…