PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Databricks

Solve Grid Path and Graph Sampling

Last updated: Apr 24, 2026

Quick Overview

This question evaluates graph algorithms and probabilistic/combinatorial reasoning, covering multi-criteria shortest-path optimization (minimizing travel time with a secondary fee objective) and uniform random sampling of edge sets that connect disjoint components.

  • medium
  • Databricks
  • Coding & Algorithms
  • Software Engineer

Solve Grid Path and Graph Sampling

Company: Databricks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

This interview note described two coding problems: 1. **Grid path with shortest time and lowest cost** You are given an `m x n` grid containing a start cell `S`, an end cell `E`, blocked cells, and open cells. You may move up, down, left, or right to adjacent open cells. Each move takes exactly 1 unit of time. Some cells also have a non-negative fee that is paid when you enter that cell. Find a path from `S` to `E` that minimizes total travel time; among all shortest-time paths, choose one with the minimum total fee. Return the minimum time and minimum fee, or report that no path exists. 2. **Uniformly sample edges that connect multiple components** You are given `n` disjoint connected undirected graphs `G1, G2, ..., Gn`. You may add edges only between vertices belonging to different graphs, and any such cross-graph edge is allowed. Write a function that returns a random set of exactly `n - 1` new edges such that, after adding them, the union of all `n` graphs becomes connected. The returned edge set must be sampled **uniformly** from the set of all valid connecting edge sets of size `n - 1`.

Quick Answer: This question evaluates graph algorithms and probabilistic/combinatorial reasoning, covering multi-criteria shortest-path optimization (minimizing travel time with a secondary fee objective) and uniform random sampling of edge sets that connect disjoint components.

Related Interview Questions

  • Design an n x n Tic-Tac-Toe Game - Databricks (medium)
  • IPv4 CIDR Range Membership Queries - Databricks (medium)
  • Optimal Commute: Nearest Transit Distance in a City Grid - Databricks (medium)
  • Choose the Best Travel Mode - Databricks (medium)
  • Implement an Alternating Tic-Tac-Toe Game - Databricks (hard)
|Home/Coding & Algorithms/Databricks

Solve Grid Path and Graph Sampling

Databricks logo
Databricks
Apr 3, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
3
0
Practice Read
Loading...

This interview note described two coding problems:

  1. Grid path with shortest time and lowest cost
    You are given an m x n grid containing a start cell S , an end cell E , blocked cells, and open cells. You may move up, down, left, or right to adjacent open cells. Each move takes exactly 1 unit of time. Some cells also have a non-negative fee that is paid when you enter that cell. Find a path from S to E that minimizes total travel time; among all shortest-time paths, choose one with the minimum total fee. Return the minimum time and minimum fee, or report that no path exists.
  2. Uniformly sample edges that connect multiple components
    You are given n disjoint connected undirected graphs G1, G2, ..., Gn . You may add edges only between vertices belonging to different graphs, and any such cross-graph edge is allowed. Write a function that returns a random set of exactly n - 1 new edges such that, after adding them, the union of all n graphs becomes connected. The returned edge set must be sampled uniformly from the set of all valid connecting edge sets of size n - 1 .

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Databricks•More Software Engineer•Databricks Software Engineer•Databricks Coding & Algorithms•Software Engineer Coding & Algorithms
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.