PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates expertise in string algorithms, multiset equality, algorithmic time/space complexity analysis, memory- and streaming-aware algorithm design, Unicode normalization and case folding, and approximate string matching for k‑off anagrams.

  • Medium
  • Uber
  • Coding & Algorithms
  • Data Scientist

Check anagrams under real-world constraints

Company: Uber

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given two strings s and t, determine whether they contain exactly the same multiset of characters (e.g., 'abc' and 'cab' → true; 'aab' and 'ab' → false). Provide: (a) an O(n) solution and its time/space complexity; (b) an approach when the character set is large or unknown (Unicode) and inputs may require normalization/case‑folding; (c) a streaming variant where s and t arrive as streams and memory is limited (sublinear in n); and (d) a solution when sorting is disallowed and only O(1) extra space is permitted (explain assumptions needed). Then extend to decide if s and t are "k‑off" anagrams (they become anagrams after at most k single‑character insertions/deletions). Discuss trade‑offs of each approach.

Quick Answer: This question evaluates expertise in string algorithms, multiset equality, algorithmic time/space complexity analysis, memory- and streaming-aware algorithm design, Unicode normalization and case folding, and approximate string matching for k‑off anagrams.

Return whether two strings are anagrams. If k > 0, allow at most k insertions or deletions to make them anagrams.

Constraints

  • Inputs are strings
  • k counts single-character insertions/deletions

Examples

Input: ('abc', 'cab', 0, False)

Expected Output: True

Explanation: Same multiset.

Input: ('aab', 'ab', 0, False)

Expected Output: False

Explanation: Different counts.

Input: ('aab', 'ab', 1, False)

Expected Output: True

Explanation: One deletion fixes the mismatch.

Input: ('Listen', 'silent', 0, True)

Expected Output: True

Explanation: Optional case-folding.

Input: ('', '', 0, False)

Expected Output: True

Explanation: Empty strings.

Hints

  1. A character frequency difference gives the number of insertions/deletions needed.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
  • Design and Implement an LRU Cache - Uber (medium)
  • Reconstruct the Alphabet Order of an Alien Language - Uber (medium)
  • Maximize Throughput and Count Trigger Components - Uber (medium)