ProgrammingHardTCS NQT · Accenture
The words of "the sky is blue" are reversed in order (the words themselves are kept). The procedure below does this and prints the result. What is printed?
The words of "the sky is blue" are reversed in order (the words themselves are kept). The procedure below does this and prints the result. What is printed?
split the sentence into words; reverse the list; join with single spaces Print result
- A. eulb si yks eht
- B. eht yks si eulb
- C. blue is sky the
- D. the sky is blue
Correct answer: C. blue is sky the
Reversing the list of words gives blue is sky the. Reversing the whole string reverses the letters too, reversing each word keeps the word order, and the original sentence is unchanged.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The string "bananana" is searched for "ana" with overlapping occurrences allowed. The procedure below counts the start positions of…
- Strings are compressed in place by writing each run of equal characters as the character followed by the run length (a count of 1 is…
- Using Booth-style thinking, the lexicographically smallest rotation of the string "banana" is wanted. The procedure below tries every…
- The word "mississippi" is examined by the procedure below, which counts how many different letters it contains. What is printed? seen =…
- A palindrome check on "racecar" uses two pointers from both ends, comparing one pair per step and stopping early on a mismatch. The…
- The string "abcabcbb" is scanned with a sliding window that keeps the longest stretch without a repeated character. The procedure below…