FastPrepN-ary Index-Path Encoder and Decoder
Problems/N-ary Index-Path Encoder and Decoder

N-ary Index-Path Encoder and Decoder

Bloomberg LP logoBloomberg LP● MediumNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives an ordered N-ary tree encoder and decoder with a * root, paths made of child indexes, unique leaves A-Z, and an example where path 01 decodes to a letter. It does not say how to write the tree or what to do with bad input. We used parallel arrays, a finite list of encode and decode operations, and valid one-digit paths. Our version is about 90% the same as the reported question.

An ordered N-ary tree is represented by parallel arrays. Node 0 is the root. values[i] is * for an internal node or one uppercase English letter for a leaf. children[i] lists node i's children in index order. Every node has at most ten children, every leaf letter is unique, and internal nodes are not operation targets.

A letter's code is the sequence of child indices on the path from the root to that letter. Each index is one digit from 0 through 9. Process operations in order:

  • ["ENCODE", letter] returns that letter's code.
  • ["DECODE", code] follows the code from the root and returns the reached letter.

Every operation is valid: encoded letters exist uniquely, and decoded paths end at letter leaves. Return one string for every operation in encounter order.

Function

processNaryCodec(values: String[], children: int[][], operations: String[][]) → String[]

Examples

Example 1

values = ["*","*","A","B","C"]children = [[1,4],[2,3],[],[],[]]operations = [["DECODE","01"],["ENCODE","C"],["ENCODE","A"]]return = ["B","1","00"]

Path 01 selects root child 0, then its child 1, reaching B. Letter C is root child 1.

Example 2

values = ["*","X","Y","Z"]children = [[1,2,3],[],[],[]]operations = [["ENCODE","Y"],["DECODE","2"],["ENCODE","X"]]return = ["1","Z","0"]

All letters are direct root children, so each code is its zero-based child position.

Example 3

values = ["*","*","*","Q"]children = [[1],[2],[3],[]]operations = [["DECODE","000"],["ENCODE","Q"]]return = ["Q","000"]

The single-letter leaf is reached through three successive child-zero choices.

Constraints

  • 2 <= values.length <= 100000.
  • children.length == values.length, node 0 is *, and the arrays form one valid rooted tree.
  • Every internal node has between 1 and 10 children; every leaf is a unique uppercase English letter.
  • 1 <= operations.length <= 100000.
  • Every operation is valid, and the total length of all input and output paths is at most 500000.

More Bloomberg LP Onsite Interview questions

  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Search for an Element in a StreamAmazon · PHONE SCREEN

Interview reports that mention this question

  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg New Grad OOD Follow-ups: 14 Experiences (Part 3 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[] processNaryCodec(String[] values, int[][] children, String[][] operations) {
        // Write your code here.
    }

}
Checking account…