Do Two Strings Contain the Same Characters?
Problem Description​
Write a function that accepts two String
parameters and returns true
if they contain the same characters in any order, taking into account letter case.
Input​
- Two strings:
String1
String2
Output​
- A boolean value:
true
if the two strings contain the same characters in any order, considering letter case; otherwise,false
.
Constraints​
- The comparison should take letter case into account.
- Strings may contain alphanumeric characters and spaces.
Example​
Input:
"abca"
"abca"Output:
trueExplanation:
Both strings contain the same characters 'a', 'b', 'c', and 'a' in the same frequency.
Input:
"abc"
"cba"Output:
trueExplanation:
Both strings contain the same characters 'a', 'b', and 'c' in any order.
Input:
"a1 b2"
"b1 a2"Output:
trueExplanation:
Both strings contain the same characters 'a', '1', ' ', 'b', and '2' in any order.
Input:
"abc"
"abca"Output:
falseExplanation:
The first string does not contain as many 'a's as the second string.
Input:
"abc"
"Abc"Output:
falseExplanation:
The comparison is case-sensitive, so 'a' and 'A' are considered different characters.
Input:
"abc"
"cbAa"Output:
falseExplanation:
The first string does not contain as many characters as the second string, and the comparison is case-sensitive.