Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "abcdefghij" is read two letters at a time in pairs; each pair (xy) is replaced by the pair reversed (yx). What is the resulting string?
- A. abcdefghij
- B. jihgfedcba
- C. badcfehgji
- D. bacdfeghij
Correct answer: C. badcfehgji
Each consecutive pair is swapped in place, so 'ab' becomes 'ba', 'cd' becomes 'dc', and so on. Reversing the whole string instead gives a different result.
More Coding Interview Problems questions
- Problem: The sum of the numbers in the sequence 1, 1+2, 1+2+3, …, up to 1+2+…+12 is what value?
- Problem: In the array [2, 4, 6, 8, 10], count the number of subarrays whose sum is divisible by 4.
- Problem: A stack-based bracket checker reads the string "([]{()})[" and reports the number of unmatched opening brackets at the end (0 if…
- Problem: An LRU cache of capacity 2 handles requests 1, 2, 1, 3, 2, 1, 4. Each request that is not cached causes a miss and evicts the…
- Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?