Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

String Permutation Check Optimization

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

Your question is String Permutation Check Optimization. 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

Airtel Digital processes short text values such as notification tokens and user-entered labels. Given two strings, determine whether the second string is a permutation of the first, meaning both contain exactly the same characters with the same frequencies, possibly in a different order.

Implement are_permutations(s, t) and optimize the solution for linear time complexity.

Formal Specification

  • Input: Two strings s and t containing only lowercase English letters (a through z).
  • Output: Return True if t is a permutation of s; otherwise, return False.
  • Character order does not matter, but character frequency does. For example, "aab" and "aba" are permutations, while "aab" and "abb" are not.

Constraints

  • 0 <= len(s), len(t) <= 10^5
  • s and t contain only lowercase English letters
  • Return a boolean result
  • Target time complexity is O(n)

Function Signature

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