PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Google

Optimize 0/1 to bounded knapsack DP

Last updated: Mar 29, 2026

Quick Overview

This question evaluates mastery of dynamic programming for knapsack problems, focusing on state formulation, space-time optimization, and reconstructing optimal item sets.

  • Medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Optimize 0/1 to bounded knapsack DP

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Solve the 0/1 knapsack problem: given arrays weight[i], value[i] for i=0..n-1 and capacity W, return the maximum value and reconstruct one optimal set of item indices. Provide both O(nW) time/O(nW) space and O(nW) time/O(W) space solutions. Next, extend your solution to the bounded knapsack variant where each item i has a limited count count[i]. Implement an O(nW) approach using binary decomposition of counts (or another efficient method), and explain the complexity and memory trade-offs. Dry-run both variants on: weight=[2,3,4], value=[4,5,10], W=7 (0/1 case), then count=[3,1,2] (bounded case).

Quick Answer: This question evaluates mastery of dynamic programming for knapsack problems, focusing on state formulation, space-time optimization, and reconstructing optimal item sets.

Related Interview Questions

  • Solve Flower Placement and Directory Deletion - Google (medium)
  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Implement Checksums and Feature Rollout Evaluation - Google (medium)
Google logo
Google
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

Solve the 0/1 knapsack problem: given arrays weight[i], value[i] for i=0..n-1 and capacity W, return the maximum value and reconstruct one optimal set of item indices. Provide both O(nW) time/O(nW) space and O(nW) time/O(W) space solutions. Next, extend your solution to the bounded knapsack variant where each item i has a limited count count[i]. Implement an O(nW) approach using binary decomposition of counts (or another efficient method), and explain the complexity and memory trade-offs. Dry-run both variants on: weight=[2,3,4], value=[4,5,10], W=7 (0/1 case), then count=[3,1,2] (bounded case).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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