U

119. Check If Two Strings Are Anagrams

Easy

Problem Description

Given two strings SS and TT, determine whether TT is an anagram of SS.

Input Format

  • •Line 1: String SS.
  • •Line 2: String TT.

Output Format

Print true if anagrams, else false.

Example 1:
Input:
anagram
nagaram
Output:
true
Explanation: Same character frequencies.
Example 2:
Input:
rat
car
Output:
false
Explanation: Characters differ.
Example 3:
Input:
a
a
Output:
true
Explanation: Identical single character.
Constraints:
  • Standard integer bounds: 32-bit signed integer or input range [1, 10^5].
  • Time complexity target: O(N) or O(N log N) where applicable.
  • Auxiliary space target: O(1) or minimal auxiliary memory.
Follow up:Can this algorithm be adapted to an online streaming setting where the entire input cannot be held in memory simultaneously?
1,180 Online