PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Machine Learning/Cresta

Design sequence decoding with greedy and beam search

Last updated: Mar 29, 2026

Quick Overview

This interview question evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer for Design sequence decoding with greedy and beam search states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • medium
  • Cresta
  • Machine Learning
  • Software Engineer

Design sequence decoding with greedy and beam search

Company: Cresta

Role: Software Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Technical Screen

You are given a probabilistic next-token dictionary D that maps each token t to a dictionary of candidate next tokens {u: p(u|t)}. Use '<START>' as the start token and '.' as the end-of-sequence token. 1) Implement greedy decoding that, starting from '<START>', repeatedly selects the highest-probability next token until '.' is produced or no continuation exists. Provide both a recursive and an iterative version, and return the sequence of tokens (include '.' if produced). Analyze time and space complexity. 2) Implement beam search decoding with beam width k using a BFS-style expansion: at each decoding step, maintain up to k highest-scoring partial sequences ranked by cumulative log-probability, expand each by its top-k next tokens from D, and continue until all beams end with '.'. Return the best sequence and optionally the top-k sequences. Explain how you handle ties, tokens missing from D, potential cycles or dead-ends, score normalization (e.g., length normalization), and termination criteria. Compare greedy and beam search in terms of quality, complexity, and typical use cases, and demonstrate your implementations on a small example dictionary.

Quick Answer: This interview question evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer for Design sequence decoding with greedy and beam search states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Related Interview Questions

  • Implement greedy and beam decoding - Cresta (medium)
|Home/Machine Learning/Cresta

Design sequence decoding with greedy and beam search

Cresta logo
Cresta
Aug 8, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenMachine Learning
76
0

Design sequence decoding with greedy and beam search

Next-Token Decoding: Greedy and Beam Search

Context

You are given a probabilistic next-token dictionary D that maps each token t to a dictionary of candidate next tokens and their conditional probabilities: D[t] = {u: p(u | t)}. Use '<START>' as the start token and '.' as the end-of-sequence token. Assume probabilities in each D[t] sum to 1. If a token does not appear as a key in D, it has no continuations (dead-end).

Tasks

  1. Greedy Decoding
  • Starting from ' <START> ', repeatedly select the highest-probability next token until '.' is produced or no continuation exists.
  • Provide both a recursive and an iterative version.
  • Return the sequence of tokens after ' <START> ' (include '.' if produced).
  • Analyze time and space complexity.
  1. Beam Search Decoding (beam width k)
  • Use a BFS-style expansion: at each decoding step, maintain up to k highest-scoring partial sequences ranked by cumulative log-probability.
  • Expand each active beam by its top-k next tokens from D; continue until all beams end with '.'.
  • Return the best sequence and optionally the top-k sequences.
  • Explain how you handle:
    • Ties
    • Tokens missing from D (dead-ends)
    • Potential cycles
    • Score normalization (e.g., length normalization)
    • Termination criteria
  • Compare greedy vs. beam search in quality, complexity, and typical use cases.
  • Demonstrate your implementations on a small example dictionary.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask

  • Clarify the task, data shape, labels, constraints, and evaluation metric.
  • State assumptions behind the math or modeling technique you choose.
  • Connect theory to practical training, debugging, and deployment implications.

What a Strong Answer Covers

  • Correct definitions and formulas where the prompt requires them.
  • A practical explanation of how the method behaves on real data.
  • Trade-offs, failure modes, diagnostics, and mitigation strategies.
  • Evaluation choices that match the product or modeling objective.

Follow-up Questions

  • How would noisy labels, class imbalance, or distribution shift affect the answer?
  • What would you monitor after deployment?
  • Which baseline would you compare against first?
Loading comments...

Browse More Questions

More Machine Learning•More Cresta•More Software Engineer•Cresta Software Engineer•Cresta Machine Learning•Software Engineer Machine Learning

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
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.