ProgrammingHardAccenture · Cognizant pattern
What will be the output of the following pseudocode (reversing the order of words in a sentence)?
What will be the output of the following pseudocode (reversing the order of words in a sentence)?
String s = "the sky is blue" List words = split(s, " ") reverse(words) Print join(words, " ")
- A. blue is sky the
- B. the sky is blue
- C. eulb si yks eht
- D. blue sky is the
Correct answer: A. blue is sky the
Splitting on spaces gives {'the','sky','is','blue'}; reversing that list gives {'blue','is','sky','the'}, which joined with spaces is 'blue is sky the'.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode (number of ways to make change for an amount using given coin denominations, counting…
- What will be the output of the following pseudocode (length of the longest common SUBSTRING, i.e. contiguous, not subsequence)? Function…
- What will be the output of the following pseudocode (counting distinct ordered character pairs (s[i], s[j]) with i<j)? (Strings are…
- What will be the output of the following pseudocode (capitalizing the first letter of each word, manually)? String s = "hello world foo"…
- What will be the output of the following pseudocode (maximum sum of any 4 consecutive elements, sliding window)? (Arrays are indexed from…
- What will be the output of the following pseudocode (reversing an array in groups of size k)? (Arrays are indexed from 0.) Integer arr[8]…