Practice Form Largest Integer With Digits That Add up to Target
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#1449
LeetCode ProblemForm Largest Integer With Digits That Add up to Target
Problem Statement
Painting digit d, for d from 1 through 9, costs cost[d - 1]. Construct the greatest possible integer using these digits with total cost exactly target; digit 0 cannot be used. Return the integer as a string, or "0" if no such integer can be constructed.
Source: Form Largest Integer With Digits That Add up to Target on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
cost = [4,3,2,5,6,7,2,5,5], target = 9
Output
"7772"
# Example 2
Input
cost = [7,6,5,5,5,6,8,7,8], target = 12
Output
"85"
# Example 3
Input
cost = [2,4,6,2,4,6,4,4,4], target = 5
Output
"0"
Constraints
cost.length == 9
1 <= cost[i], target <= 5000
Related LeetCode Problems
Practice more problems similar to Form Largest Integer With Digits That Add up to Target.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.