Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by YetAnotherNick on Friday September 12, 2025 @11:32AM
(#45223241)
General constraint solver would be terribly inefficient for problems like these. It's a linear problem and constraint solver just can't handle O(10^6) variables without some beefy machine.
[ Parent
| on HN ]
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by nextos on Friday September 12, 2025 @12:06PM
(#45223661)
FWIW, the OP's problem is not linear. It's an integer programming problem given that coins are discrete.
A trick if you can't do a custom algorithm and using a library is not allowed during interview could be to be ready to roll your own DPLL-based solver (can be done in 30 LOC).
Less elegant, but it's a one-size-fits-all solution.
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by kragen on Friday September 12, 2025 @05:20PM
(#45226900)
You can implement DPLL in 30 lines of code? Not for SMT, I assume.
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by nextos on Friday September 12, 2025 @10:09PM
(#45228747)
You'd need a fancy encoding for SAT to use a small DPLL implementation.
Otherwise, customize DPLL for this particular problem.
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by NoahZuniga on Friday September 12, 2025 @11:40AM
(#45223364)
O(10^6) = O(1)
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by dekhn on Friday September 12, 2025 @11:43AM
(#45223403)
no, the "O" here is "on the order of", not Big O notation.
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by harperlee on Friday September 12, 2025 @12:05PM
(#45223652)
I believe NoahZuniga is perfectly aware of the intent and denouncing an abuse of (unneeded) notation.
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by anonymars on Friday September 12, 2025 @01:12PM
(#45224312)
What is "Big O" if not literally "order of"?
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by dekhn on Friday September 12, 2025 @01:57PM
(#45224746)
In physics "order of" means "approximately" using something like a taylor series, which typically start with a constant, then move to higher polynomial terms which add smaller and smaller corrections. Similar, but different, I think...
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by NoahZuniga on Friday September 12, 2025 @01:18PM
(#45224374)
The O stands for "Ordnung", the German word for order. So it does literally mean that, except mathematicians think that the order of f(x)=1 is the same as the order of f(x)=10^6, because "clearly" f(x)=x gets way bigger than any constant function.
Re:Many Hard LeetCode Problems Are Easy Constraint Problems
by OutOfHere on Friday September 12, 2025 @11:40AM
(#45223352)
Okay, but who says you need to use a simple constraint solver? There are various sophisticated constraint solvers that know how to optimize.
At this point, job interviews are so far removed from actual relevance. Experience and aptitude still matter a lot, but too much experience at one employer can ground people in rigid and limiting ways of thinking and solving problems.