PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Oracle

Count anagram-based replacements per phrase

Last updated: Mar 29, 2026

Quick Overview

This question evaluates skills in string processing, anagram grouping, frequency mapping, and combinatorial counting to determine how many phrase variations arise from permissible replacements in the Coding & Algorithms domain.

  • medium
  • Oracle
  • Coding & Algorithms
  • Software Engineer

Count anagram-based replacements per phrase

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given: - `phrases`: a list of strings, where each string is a phrase containing words separated by single spaces. - `words`: a list of strings. A word `a` can be **replaced** by a word `b` if `a` and `b` are **anagrams** (they contain the same letters with the same frequencies; order does not matter). For each phrase, compute how many different phrases can be formed by replacing **each replaceable word** in the phrase with **any** anagram from `words`. - Words in the phrase that have **no anagram in `words`** must stay unchanged. - If **no word** in the phrase has any anagram in `words` (i.e., no replacement is possible), return `0` for that phrase. Return a list of integers, one per phrase. ### Example Input: - `phrases = ["hello world", "below elbow"]` - `words = ["below", "elbow"]` Explanation: - Phrase 1: neither `hello` nor `world` has an anagram in `words` → no replacement possible → `0` - Phrase 2: `below` and `elbow` are anagrams, and both appear in `words`. Each of the two positions can be replaced by either `below` or `elbow` → `2 * 2 = 4` Output: - `[0, 4]` ## Requirements / Notes - Treat anagrams case-sensitively or case-insensitively consistently (state your choice in implementation; a common assumption is lowercase inputs). - You may assume phrases contain only alphabetic words and spaces. - The result may exceed 32-bit integer range; use 64-bit if needed.

Quick Answer: This question evaluates skills in string processing, anagram grouping, frequency mapping, and combinatorial counting to determine how many phrase variations arise from permissible replacements in the Coding & Algorithms domain.

Related Interview Questions

  • Solve Five Coding Problems - Oracle (medium)
  • Compute letter frequencies from encoded string - Oracle (medium)
  • Count closed islands in a grid - Oracle (easy)
  • Implement in-memory data structures and booking API - Oracle (hard)
  • Implement an LRU cache - Oracle (medium)
Oracle logo
Oracle
Dec 15, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0

Problem

You are given:

  • phrases : a list of strings, where each string is a phrase containing words separated by single spaces.
  • words : a list of strings.

A word a can be replaced by a word b if a and b are anagrams (they contain the same letters with the same frequencies; order does not matter).

For each phrase, compute how many different phrases can be formed by replacing each replaceable word in the phrase with any anagram from words.

  • Words in the phrase that have no anagram in words must stay unchanged.
  • If no word in the phrase has any anagram in words (i.e., no replacement is possible), return 0 for that phrase.

Return a list of integers, one per phrase.

Example

Input:

  • phrases = ["hello world", "below elbow"]
  • words = ["below", "elbow"]

Explanation:

  • Phrase 1: neither hello nor world has an anagram in words → no replacement possible → 0
  • Phrase 2: below and elbow are anagrams, and both appear in words . Each of the two positions can be replaced by either below or elbow → 2 * 2 = 4

Output:

  • [0, 4]

Requirements / Notes

  • Treat anagrams case-sensitively or case-insensitively consistently (state your choice in implementation; a common assumption is lowercase inputs).
  • You may assume phrases contain only alphabetic words and spaces.
  • The result may exceed 32-bit integer range; use 64-bit if needed.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Oracle•More Software Engineer•Oracle Software Engineer•Oracle Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.