Skip to main content
Back to problems
Leetcode
Medium
Strings
Arrays
Hash Maps
Check Digitorial Permutation

Determine whether one string is a permutation of another by comparing character counts.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

Given two strings, determine whether one string is a permutation of the other.

Two strings are permutations of each other if they contain exactly the same characters with the same frequencies, possibly in a different order.

Return true if the strings are permutations of each other; otherwise, return false.

Notes

  • You may assume the comparison is case-sensitive unless stated otherwise.
  • Characters should be matched exactly, including spaces or symbols if they appear in the input.
  • A valid solution should work efficiently for long strings.

Input Format

  • Two strings s and t
  • The strings may be provided as separate lines or as fields in a JSON-style input, depending on the platform

Output Format

  • Return a boolean value: true if s is a permutation of t, otherwise false

Constraints

  • 0≤∣s∣,∣t∣0 \le |s|, |t|
  • The solution should be efficient for large inputs
  • Character set and exact limits may vary by platform
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "abc"
t = "bca"

Output

true

Explanation

Both strings contain one a, one b, and one c, so they are permutations of each other.

Example 2

Input

s = "aab"
t = "aba"

Output

true

Explanation

Both strings have the same character counts: two a characters and one b character.

Show 1 more example

Example 3

Input

s = "abc"
t = "abd"

Output

false

Explanation

The character counts differ because c appears in s but d appears in t.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.