Maximize rental income given a set of date intervals

Suppose you have 1 room that you want to rent out. (AirBnb style) You want to maximize profits that you will get by renting it out.

For example: Given intervals: [[1, 10], [2, 5], [7, 20], [23, 30]] – you could rent it out [2, 5], [7, 20] and [23, 30]

Another example: ([[1, 2], [1, 11], [5, 8], [4, 33], [18, 72]]) = 66

Note: Start and end times of the interval are inclusive

I implemented a brute force solution to this problem. First I sort by start time, then I create all possible subsets and take the longest possible value. This works. But I want to do this using Dynamic programming.

This problem screams DP, but I am not able to figure out if this has an optimal substructure.

My recurrence relation: f(i, j) = f(i + 1, j) or f(i + nums[i], j) if nums[i].start > f[i].end

Can someone help me figure out the thought behind the dp solution for the sub-problem?

Note: this problem is slightly different from job scheduling.

tracking in odi the package which uses a given mapping

I am trying to find the whole lineage and loading process of a certain table column. To begin with i am locating the mapping used to populate the column. To do this i use:

select mapping_name,     mr.qualified_name, datastore_alias,     t.table_name target_table,     mdl.cod_mod model_code from snp_mapping m inner join snp_map_comp mc on m.i_mapping = mc.i_owner_mapping     inner join snp_map_cp cp on mc.i_map_comp = cp.i_owner_map_comp     inner join snp_map_ref mr on mc.i_map_ref = mr.i_map_ref     inner join snp_table t on mr.i_ref_id = t.i_table     inner join snp_model mdl on t.i_mod = mdl.i_mod where cp.direction = 'O' and --output connection point     cp.i_map_cp not in         (select i_start_map_cp from snp_map_conn) --not a starting connection point; 

which works very nice. (Thread found here :

Now i need to find the package which uses this mapping, so that i will be able to investigate the whole loading process. So the question is: is there a query which can return the packages that use the mapping defined?. I did find an SNP_PACKAGES table but i am not sure if i can get anything from there.

How do I input a 2d matrix when no spacing is given in adjacent elements while taking the input in c++?

Thanks for looking over, so I’m trying to take a nxn matrix as input where in the input is in the following format example :

4 1123 3442 5632 2444 

you see the input format that’s my problem I don’t want those elements to be stuck together and c++ is reading the rows as if each of the row is a number which means “cin” is reading only n elements and I expect it to read all n×n elements to be read separately. Pardon me if the question wasn’t upto the mark as this is my first question.

Query: Given a graph, is edge x in an optimal TSP tour?

Consider the decision problem that when given a graph, we need to decide if a particular edge belongs to any optimal solution to the traveling salesman problem on that graph.

It may be argued that the complexity of this problem is strictly greater than any co-NP problem. The idea is that it’s perhaps impossible to come up with a counter-example, since we need e.g. an optimal tour candidate before we can consider a counterexample (but no optimal tour candidate is given in this problem statement).

On the other hand, it may be argued that the complexity of this problem is strictly smaller than any P-space-complete problem, as our problem may be seen as

$ \exists$ “a tour A containing x” $ \forall$ “tours B”: (some formula stating that A <= B)

whereas some probably “minimal” P-space-complete problem has O(n) alternations of $ \exists$ and $ \forall$ : the quantified boolean formula problem (QBF).

Based on this argument, is it reasonable to expect that there’s a complexity class between co-NP and PSPACE? Does this particular class have a name? Can we expect to find arbitrarily more such classes by adding another one alternation of $ \forall$ or $ \exists$ to the previously found such class?

How can I predict javascript Math.random method given integers?

I know this is possible because people have mentioned doing it. Given the XorShift128+ algorithm, how can I predict the next numbers given 15 integers generated through Math.floor(Math.random() * (max - min +1) + min). I have tried modifying this script into this, however my code doesn’t work and is stuck solving infinitely. Any help would be appreciated.

How to get data from database week wise between two given dates?

I have a SQL database where i saved data of all dates in table. What i want is, If given any two dates, i want all the data between those two dates in weekly format where week starts on Monday. if given date starts with Thursday for example, so data from Thursday to sunday should be displayed as a week data.

I give you one example. If i choose start date 08-01-2020 and end date 08-03-2020. Now this is two months gap and there are probably 30 days. I want data of those 30 days, but week wise from Monday to Sunday. But here given start date is on Wednesday, so the that weeks data would start from wednesday and end on sunday.

Hope you got my point. Thanks in advance.

What is the best of given hashfunctions?

In our exam on algorithms there was a question, where given 3 hashfunctions we had to chose one and explain why it’s the best.

h_1(x,i)=(x+5*i) mod 1000
h_2(x,i)=(x+17*i) mod 1000
h_3(x,i)=(x+32*i) mod 1000

I am really unsure about this, but I suspect that it is the second one, because it can “hit” more values. If I choose the first one for example, I will be hitting the same buckets over and over (if they are full). Question seems quite simple but my math lecture on this has been a long time ago.

Confusion with “every path from a given node to any of the leaves goes through the same number of black nodes” property of RB trees

One of the properties of Red Black trees is: “every path from a given node/vertex to any of the leaves goes through the same number of black nodes”

Two related questions about this property:

1) is the vertex we start at counted in this black vertex count?

2) is the leaf we end at counted in the black vertex count?

I have a secret theory about both of these questions, but am hoping for confirmation and so shalt not yet reveal it.

Construct a DAG from given multiple topological orderings

I need to construct a DAG, using the given topological orderings. For simplicity, the vertices are labeled as first $ n$ natural numbers
The following constraints should be met:

  1. The maximum outdegree of every node should be 1
  2. The number of nodes having indegree 0 should be minimum.

There can be multiple solutions, any of them should work.

What I have tried.

From all the given orderings, first, create a directed graph by creating a directed edge from every node to its next node. This means if the orderings are:
$ $ 1, 3, 2, 5, 4, 6 $ $ $ $ 3, 1, 5, 2, 4, 6 $ $ $ $ 1, 5, 3, 2, 4, 6 $ $

I will create a directed graph:

enter image description here

This ensures that the number of nodes with indegree 0 remains minimum. Now, I’ll remove all the cycles and make sure all the orderings are valid and finally, eliminate all the extra edges any node has. WHile doing so, I’ll make sure that if there are two nodes whose edge is coming from the same node, I’ll remove the edge from the node having a higher indegree, so that condition 2 is met. The graph constructed then, should look like: enter image description here

This DAG created, follows both the constraints, and IMO has the minimum number of nodes of indegree as 0, although, it’s not proven.

I have coded the approach and it is giving expected results for the use cases I supply, but I know that it is wrong. What am I missing here? Can anyone provide an alternative use case, which fails the above approach?