Skip to main content
6 votes
Accepted

Is 'call site' compiler generated auto code?

“Call site” refers to the place where a function or method is called. It is a common term in compiler construction, and not specific to C#. foo(); // call site void foo() { ... } // function ...
amon's user avatar
  • 136k
3 votes
Accepted

Merging algorithm for overlapping intervals

How does the dynamic array matter? You'll still want to store the values in sorted ascending order. Then it should be a relatively straightforward binary search to find the closest intervals (based ...
Telastyn's user avatar
  • 110k
3 votes

design problem handling a dynamic object

I prefer to validate in the constructor. The idea behind that is then you know that the object state is valid because the object exists. Now maybe you can’t validate at the client for some reason. ...
candied_orange's user avatar
3 votes

Algorithm – Number of strings containing every string of a given set a strings

Well, any of the strings from S that your target string has to contain must start at some index i < l, right? So just start searching states of the world where the first string is at index 0, 1, 2 ...
Kilian Foth's user avatar
3 votes

Optimal sequence of recipes

This problem can be modeled as a longest path search in a directed graph. Each vertex of the graph corresponds to a set of currently available resources (starting with the empty set), and the recipes ...
Doc Brown's user avatar
  • 218k
2 votes
Accepted

How should I apply dynamic programming on the following problem

This is a O(n^3) approach The time complexity has to do with k as well. The DP should give you a O(nk) instead. Similar with a knapsack problem, you can use a recursive way with memorization to ...
lennon310's user avatar
  • 3,242
2 votes

What to memoize in Dynamic programming questions?

Memoization is an optimization, not a solution. what to memoize isn’t that obvious Write the solution first, and then memoize whatever you redundantly compute more than once. Trying to skip the ...
Useless's user avatar
  • 12.8k
1 vote

Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general

I'm trying to provide an intuitive answer to your intuitive question here, because you're not asking how to solve the problem but rather why recursion is not the favored way of doing so. Let's explore ...
Flater's user avatar
  • 58.1k
1 vote

Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general

There are a number of skills/techniques/experiance that will help with Leetcode style problems, specifically: Being able to switch between imperative and functional (recursive) forms - sometimes one ...
DavidT's user avatar
  • 4,496
1 vote

Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general

It sounds like you're not happy with the solutions you're coming up with. Even when they work they aren't fast enough to make you happy. Keep demanding perfection and you're sure to maintain your ...
candied_orange's user avatar
1 vote
Accepted

Given n points in Cartesian 2D coords and only able to move directly from point to point how can you reach any point while minimising the longest jump

So input of your algorithm is "O" as starting point, "T" as the target point, and a set of intermediate points. I would try the following approach: Create the list of all segments ...
Doc Brown's user avatar
  • 218k
1 vote

Algorithm – Number of strings containing every string of a given set a strings

I don't see an easy way to efficiently do this. The closest I've come is the following (works for Python 3.9): from typing import Optional Template = list[Optional[str]] def possible_match(...
Jasmijn's user avatar
  • 1,869
1 vote

Calling recursive method in a loop - Backtracking

For Partition Sum Equal to K, The loop in Sol 1 means you randomly choose indices from [index, n-1] in each recursion, and loop in Sol 2 means you either choose or not choose the next index (index + 1)...
lennon310's user avatar
  • 3,242
1 vote

Is 'call site' compiler generated auto code?

The most typical use of call-site is probably that as presently declared on Wikipedia: it is nothing more than the place in some code where a call to a function or subroutine is made. It is a ...
VisualMelon's user avatar
1 vote

Find path of steepest descent along with path length in a matrix

I solved it using a memoized DFS solution. I am visualizing this matrix as a DAG with the values as nodes and a edge to NWES neighbors only if the value of the neighbor is < the value at the node. ...
Samrat Chakraborty's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible