Check Whether a Pod Fits on a GPU Node
Last updated: November 29, 2026
Quick Overview
Given a node's allocatable resources, the requests of pods already scheduled on it, and a new pod's requests, all as Kubernetes quantity strings such as 500m, 2Gi or 1, decide whether the new pod fits and which resource blocks it.
Truefoundry
November 29, 20260
0
0 solved
Given a node's allocatable resources, the requests of pods already scheduled on it, and a new pod's requests, all as Kubernetes quantity strings such as 500m, 2Gi or 1, decide whether the new pod fits and which resource blocks it.
TrueFoundry runs model servers, jobs and notebooks as Kubernetes workloads and has to tell users why a GPU deployment is pending. A warm-up question like this checks clean parsing of Kubernetes resource units and careful comparisons, which come up constantly in platform code.
What the Interviewer Expects
- Parse decimal (k, M, G) and binary (Ki, Mi, Gi) suffixes plus millicores
- Check longest suffix first so Mi is not read as M
- Treat missing resources on the node as zero capacity
- Report the first resource that does not fit
- Mention float precision and how real code avoids it
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the best node among many, not just yes or no?
- How do taints, tolerations and node selectors change the check?
- Why does Kubernetes schedule on requests rather than limits?
- How would you represent quantities exactly without floats?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Resources are maps like {"cpu": "4", "memory": "16Gi", "nvidia.com/gpu": "1"}. The new pod fits if for every resource it requests, existing requests plus its request is at most allocatable. Output `...
High-Level Design
Write a parse_quantity that converts a string to a number in base units: cores for CPU, bytes for memory, a count for extended resources like GPUs. Binary suffixes are powers of 1024, decimal ones p...