PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Microsoft

Solve budget queries and shortest path

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic design and data-structure selection for efficient preprocessing and query answering, along with shortest-path computation and graph representation choices, testing complexity analysis, large-input handling, path reconstruction, and edge-case reasoning in the Coding & Algorithms domain.

  • Medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Solve budget queries and shortest path

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

1) Budgeted purchases with sorted array: You are given an array prices of n positive integers and q budget queries. For each budget B, you may buy items starting from the cheapest price, using each item at most once, until the running total would exceed B. Return, for each query, the maximum number of items purchasable. Design an algorithm that preprocesses prices and answers all queries efficiently. Specify the data structures used, time and space complexity, and implement a function solve(prices: List[int], budgets: List[int]) -> List[int]. Consider large inputs (n, q up to 2e 5) and edge cases such as duplicate prices and budgets smaller than the minimum price. 2) Shortest path in a weighted graph: You are given a directed weighted graph with n nodes (1..n) and m edges; each edge is a triple (u, v, w) with non-negative weight w. Given source s and target t, compute the shortest path distance from s to t and also return one corresponding path. If t is unreachable, return -1 and an empty path. Choose appropriate graph representations and algorithms, justify your choices, and provide time/space complexity. Discuss how you would parse large, line-based input efficiently and how your solution changes if some edges can have negative (but no negative-cycle) weights.

Quick Answer: This question evaluates algorithmic design and data-structure selection for efficient preprocessing and query answering, along with shortest-path computation and graph representation choices, testing complexity analysis, large-input handling, path reconstruction, and edge-case reasoning in the Coding & Algorithms domain.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Aug 1, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
2
0
  1. Budgeted purchases with sorted array: You are given an array prices of n positive integers and q budget queries. For each budget B, you may buy items starting from the cheapest price, using each item at most once, until the running total would exceed B. Return, for each query, the maximum number of items purchasable. Design an algorithm that preprocesses prices and answers all queries efficiently. Specify the data structures used, time and space complexity, and implement a function solve(prices: List[int], budgets: List[int]) -> List[int]. Consider large inputs (n, q up to 2e
  2. and edge cases such as duplicate prices and budgets smaller than the minimum price.
  3. Shortest path in a weighted graph: You are given a directed weighted graph with n nodes (1..n) and m edges; each edge is a triple (u, v, w) with non-negative weight w. Given source s and target t, compute the shortest path distance from s to t and also return one corresponding path. If t is unreachable, return -1 and an empty path. Choose appropriate graph representations and algorithms, justify your choices, and provide time/space complexity. Discuss how you would parse large, line-based input efficiently and how your solution changes if some edges can have negative (but no negative-cycle) weights.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.