MEDIUMasked at 1 company

Smallest String With A Given Numeric Value

A medium-tier problem at 67% community acceptance, tagged with String, Greedy. Reported in interviews at Lendingkart Technologies and 0 others.

Founder's read

You need to build a string where each character maps to a numeric value (a=1, b=2,... z=26) and the sum equals a target. The catch: return the lexicographically smallest string. This problem hits the intersection of greedy logic and string construction. Lendingkart Technologies has asked it. The 67% acceptance rate tells you the obvious greedy approach works, but only if you apply it backwards. If you freeze on the pattern during your assessment, StealthCoder surfaces the solution in seconds while the proctor sees nothing.

Companies asking
1
Difficulty
MEDIUM
Acceptance
67%

Companies that ask "Smallest String With A Given Numeric Value"

If this hits your live OA

Smallest String With A Given Numeric Value is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The trick is counterintuitive: build the string from right to left, not left to right. Start by greedily assigning the largest possible character values (z=26) to the rightmost positions to "use up" the numeric budget as fast as possible. This frees up the left side to place small characters (a=1) and achieve lexicographic minimality. The obvious left-to-right greedy fails because you'd bloat the early characters and can't recover. Once you flip the direction, the algorithm is straightforward: loop down from 26, pack as many high-value chars as the remaining sum allows into the right positions, then fill the rest with 'a'. Greedy works here because there's no optimization conflict. If this pattern doesn't click during your live OA, StealthCoder removes the guesswork.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Smallest String With A Given Numeric Value recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Smallest String With A Given Numeric Value interview FAQ

Is this really just a greedy problem?+

Yes. The 67% acceptance rate confirms the greedy approach is sound. The bar is recognizing that you must build right-to-left, not left-to-right. Once you see that, the implementation is mechanical. Most rejects come from applying greedy in the wrong direction.

How do I know when to use greedy vs dynamic programming on string problems?+

Greedy works when a locally optimal choice (here, maximum character value from the right) leads to a globally optimal answer without creating conflicts later. This problem has no trade-off: placing large chars on the right always helps lexicographic ordering. If the problem asked for longest string with a given sum, DP would be necessary.

Why does the right-to-left trick matter?+

Lexicographic order prioritizes the leftmost character. By exhausting your numeric budget on the right side first, you guarantee the left side gets the smallest possible values. Left-to-right greedy would lock in bad characters early and leave you unable to fix them.

What's the time complexity and does it matter?+

O(numeric_value) in the worst case, since you iterate through character values and possibly through positions. For typical inputs, this is linear in output size. Lendingkart's version likely doesn't have extreme constraints, so optimization isn't the bottleneck. The bottleneck is pattern recognition.

Will I see this at other companies?+

Low public frequency outside Lendingkart in available data. But the underlying patterns, string building plus greedy construction, show up across fintech and backend interviews. If you solve this, you've internalized a technique that ports to similar constraint-satisfaction problems.

Want the actual problem statement? View "Smallest String With A Given Numeric Value" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.