ProgrammingHardAccenture · Cognizant pattern
What will be the output of the following pseudocode (anagram check via sorting)?
What will be the output of the following pseudocode (anagram check via sorting)?
Function isAnagram(String a, String b)
return sortedChars(a) == sortedChars(b)
End Function
Print isAnagram("listen", "silent"), isAnagram("hello", "world")- A. false true
- B. true true
- C. false false
- D. true false
Correct answer: D. true false
'listen' and 'silent' contain exactly the same letters, so their sorted character sequences match: true. 'hello' and 'world' have different letter sets entirely, so they don't match: false.
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 (duplicate detection using a set)? Function hasDuplicate(Array arr) Set seen = empty…
- What will be the output of the following pseudocode (maximum sum of any window of size k)? (Arrays are indexed from 0.) Integer arr[6] =…
- What will be the output of the following pseudocode (counting inversions, brute force)? (Arrays are indexed from 0.) Integer arr[5] = {2…
- What will be the output of the following pseudocode (counting pairs summing to a target, brute force)? (Arrays are indexed from 0.)…
- What will be the output of the following pseudocode (counting pattern occurrences, allowing overlaps)? Function countOcc(String text…
- What will be the output of the following pseudocode (manually parsing a signed integer string)? Function strToInt(String s) Integer sign =…