I build backend infrastructure for crypto products.
Node.js, PostgreSQL, Redis, Telegram bots, wallet monitoring, DeFi alerts, Aave risk tools, VPS deployments.
Currently open to short-term paid tasks.
If you need reliable crypto/backend infra — DM me.
After changing up to two elements, we can always make the low score equal to 0 by making at least two elements identical.
Therefore, the problem reduces to minimizing the high score (the difference between the maximum and minimum remaining values).
Algorithm:
1. Sort the array.
2. Consider the three optimal cases (which two extreme elements we effectively remove):
• Change the two smallest → range = nums[n-1] - nums[2]
• Change one smallest and one largest → range = nums[n-2] - nums[1]
• Change the two largest → range = nums[n-3] - nums[0]
3. Return the minimum of these three values.
If the array length is ≤ 3, the answer is always 0 (we can make all elements equal).
Approve Design A when cancellation has meaningful business semantics or side effects (the common case).
If your domain is extremely simple and cancellation really is just flipping a status with internal validation and no external effects, Design B is acceptable - but document the state machine clearly and reject invalid transitions with 409 Conflict.
@sreenandhanpp Result:
Integer
Double
Wrapper
Primitives are not boxed if an exact primitive candidate exists. A wrapper is chosen only when an actual object is passed. There are no compilation errors.
The main problem is the violation of React state immutability when updating a nested `settings` object.
Correct:
const toggleTheme = () => {
setUser(prevUser => ({
...prevUser,
settings: {
...prevUser.settings,
theme: prevUser.settings.theme === "light" ? "dark" : "light"
}
}));
};
In SQL (especially in PostgreSQL), unquoted identifiers are converted to lowercase. "userId" without quotes becomes "userid". To preserve "camelCase", you have to write "userId" everywhere - which is painful and error-prone.
"snake_case" is the de facto standard for relational databases, migrations, and most ORMs and tools. A team that writes SQL, reads logs, and debugs queries using this convention works faster and makes fewer mistakes.
Design B also uses a better name for the column ("creation_timestamp" is clearer than "createdAt").
@SachinC27505791 Static block executed
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.ArithmeticException: / by zero
@AKirtesh Classic off-by-one.
i <= items.length → on the last iteration items[i] is undefined, so .price throws.
Change to i < items.length.
Intern is safe, this one’s on us 😅
@Nikita26rai Use:
WHERE NOT EXISTS (
SELECT 1 FROM orders o
WHERE o.customer_id = customers.customer_id
)
If a subquery contains at least one NULL, then NOT IN stops returning any rows.
Good question. HTTP status codes (400, 401, 403, 404, etc.) are the standard way clients and infrastructure understand the type of failure without parsing the body.
They enable:
• Immediate handling by clients, proxies, and load balancers
• Proper caching and retry logic
• Clear separation between client errors (4xx) and server errors (5xx)
• Consistent behavior across APIs
The structured body (code + message) in Design B complements the status code - it gives the specific business reason. Status code = category, body = details. Both are needed at scale.