FastPrepK-th Symbol in Grammar
Problems/K-th Symbol in Grammar

K-th Symbol in Grammar

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Bloomberg new-grad report names this well-known problem directly. Our version is about 100% the same as the reported question.

Given n and k, return the k-th symbol in row n.

Row 1 contains only 0. To build the next row, replace each 0 with 01 and each 1 with 10.

Positions within a row are counted from one.

Function

kthGrammar(n: int, k: int) → int

Examples

Example 1

n = 1k = 1return = 0

The first row contains only 0, so its first symbol is the answer.

Example 2

n = 4k = 5return = 1

Row 4 is 01101001 and its fifth symbol is 1.

Constraints

  • 1 <= n <= 30.
  • 1 <= k <= 2^(n-1).

More Bloomberg LP Onsite Interview questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE 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

Similar questions at other companies

  • Multiply Without the Multiplication OperatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Raise a Number to an Integer PowerAdobe · PHONE SCREENAdobe interview questions
  • Path Between Two Nodes of a Fibonacci TreeDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Evaluate a Nested Math ExpressionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Maximum Root-to-Leaf and Leaf-to-Leaf Path SumsAmazon · ONSITE INTERVIEW
  • Find the Two Unique NumbersZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
  • Insert into a Left-Complete Binary TreeRubrik · ONSITE INTERVIEWRubrik interview questions
  • Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int kthGrammar(int n, int k) {
        // Write your code here.
    }

}
Checking account…