FastPrepFind Defenders Against Every Hostile Monster
Problems/Find Defenders Against Every Hostile Monster

Find Defenders Against Every Hostile Monster

Confluent logoConfluent● MediumFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Approximate source match: 84%. The original Confluent author describes nested monster objects with name, can_defeat children, hostile flags, and enumeration of every friendly defender against all hostile nodes. Parallel arrays are a lossless judge representation of the reported forest-shaped nesting.

A nested monster hierarchy has been flattened into three parallel arrays. names[i] is monster i's unique name, hostile[i] says whether it is hostile, and parent[i] is the index of the monster that can directly defeat it. A root has parent -1.

Defeat is transitive: if monster A can defeat B and B can defeat C, then A can defeat C.

Return the names of every non-hostile monster that can defeat every hostile monster. Preserve input order in the result.

Function

findDefenders(names: String[], parent: int[], hostile: boolean[]) → String[]

Examples

Example 1

names = ["dragon","griffin","orc","imp"]parent = [-1,0,0,2]hostile = [false,false,true,true]return = ["dragon"]

Dragon can defeat both hostile monsters through its descendants. Griffin cannot, and hostile monsters are not eligible defenders.

Example 2

names = ["atlas","guardian","rat"]parent = [-1,0,1]hostile = [false,false,true]return = ["atlas","guardian"]

Both Atlas and Guardian have Rat in their transitive can-defeat subtree.

Example 3

names = ["oak","wolf","elm","goblin"]parent = [-1,0,-1,2]hostile = [false,true,false,true]return = []

The hostile monsters lie in different trees, so no monster can defeat both.

Constraints

  • 1 <= names.length <= 200000.
  • parent.length == hostile.length == names.length.
  • Names are unique non-empty lowercase strings.
  • Each parent[i] is -1 or a valid different index.
  • The parent relations form a forest with no cycles.
  • At least one monster is hostile.

More Confluent Onsite Interview questions

  • Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Bounded Combination Sum with Signed CandidatesONSITE INTERVIEW · Seen Oct 2026
  • Detect a Silent SensorONSITE INTERVIEW · Seen Sep 2026
  • Build an Inverted Document IndexONSITE INTERVIEW · Seen Sep 2026
  • Combination Sum with Unlimited ReuseONSITE INTERVIEW · Seen Sep 2026
  • Word Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Windowed Key-Value MapPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025

Similar questions at other companies

  • Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Recursive Display SortFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Chain of CommandIMC Trading · OAIMC Trading interview questions
  • Render a Stable Comment HierarchyBobyard · PHONE SCREEN
  • Chain of CommandUber · OAUber interview questions
  • Validate a Tree From Its Parent ArrayGoogle · PHONE SCREENGoogle interview questions
  • Validate BST Node DescriptionsAirbnb · OAAirbnb interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions

Interview reports that mention this question

  • Confluent SWE OA, Coding and Design Interviews: 19 Experiences
  • Confluent Coding and System Design Questions: 33 Questions

Confluent interview experiences

  • Confluent Older Concurrency Rounds: 12 Experiences (Part 2 of 2)
  • Confluent Concurrency Interviews: 28 Experiences (Part 1 of 2)
  • Confluent File Manipulation Round (tail -n): 19 Experiences
All Confluent interview questionsSee Confluent hiring insights
Saved
class Solution {
    public String[] findDefenders(String[] names, int[] parent, boolean[] hostile) {
        // Write your code here.
    }
}
Checking account…