Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Check If It Is a Permutation

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Check If It Is a Permutation. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Poshmark may need to compare two pieces of listing text to determine whether they contain exactly the same characters in a different order. Write a function that checks whether one string is a permutation of another.

Two strings are permutations if they have the same length and every character appears the same number of times in both strings. Comparisons are case-sensitive, and spaces and punctuation count as characters.

Formal Specification

Implement are_permutations(first, second):

  • Input: Two strings, first and second.
  • Output: Return True if second is a permutation of first; otherwise, return False.

Constraints

  • 0 <= len(first), len(second) <= 100,000
  • Strings contain printable ASCII characters
  • Comparisons are case-sensitive
  • Spaces and punctuation count as characters

Function Signature

def are_permutations(first, second):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output