Problem

  • Given two strings
  • Write an algorithm to check if they are anagram
  • Two strings are anagram if they contain same characters. The order of the characters may be different

Example

  • Input: given two strings "abc" and "bca". Expected output: true
  • Input: given two strings "abc" and "bcb". Expected output: false

Approach

  • Sort two given strings
  • Compare the sorted strings

Implementation


Complexity

  • Time complexity: O(n)
  • Space complexity: O(n)