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")
  1. A. false true
  2. B. true true
  3. C. false false
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic