## How to divide a list in linear time where every element in the first part is smaller than every element in the second list

How to divide a list into to equal part (even-number list size) in linear time where every element in the first part is smaller than every element in the second part

I tried to use QuickSort but in can result in $$O(n^2)$$ time complexity.

## Design an algorithms to find the index of the first occurrence of an element greater than that key

Question: Design an efficient algorithm that takes a sorted array and a key and finds the index of the first occurrence of an element greater than that key.

The question above is taken from Elements of Programming Interviews in Python, page $$146$$. It is a variant question.

I think the question does not mention the output if the key given is the largest element in the given array.

I code using python.

``def first_k_bigger(A,key):     i, j = 0, len(A) - 1     while i < j:         mid = (i+j)//2         if A[mid] <= key:             i = mid + 1              else:             j = mid     return i ``

Idea: I use binary search to find such index. First, we find the midpoint of the array, set two pointers $$i$$ and $$j$$ to be beginning and ending of the array and compare the midpoint element with the key given.

If the midpoint is less than or equal to the key, then the key must be on the right side of midpoint. So, we set the pointer $$i$$ to be midpoint index $$+1.$$

Otherwise, if the midpoint is bigger than the key, then the key must be on the left side of midpoint. So, we set $$j$$ to be midpoint index.

Does my code above cover all possibilities?

## Have PCs Historically Played Through More Campaigns Than is Currently Typical?

I’m relatively new to D&D, only having tabletop experience with 5e and a bit of 3.5, along with some scattered exposure to earlier editions through video games.

I’ve heard references to characters adventuring through multiple campaigns, sometimes a large number of them. But as I look through the published campaigns for 5e I see a lot of suggested level references which suggest that a character might properly fit up to two adventures. For example, the introduction to Descent into Avernus expects PCs to start at level 1 and be at least level 13 by the end.

Of course different editions have very different properties that touch on this– 3.5 had a lot of postgame content published specifically to take characters beyond the “maximum” level (whether they were good mechanics or not), while 5e doesn’t (as far as I’m aware). And published adventures are hardly the core of all D&D games played across all tables. But the basic 5e approach, and the adventures published for it, suggests to me that a PC might only see 2-3 non-oneshot adventures at most.

It’s not a problem (there are any number of ways to fiddle with adventure length and character progression) but I’m curious about whether or not the game has changed in this respect.

Has D&D always had this structure of relatively few adventures/campaigns per character (as either a game design element or by popular play style), or did a transition take place at some point? If there was a transition, when did it take place and what was the motivation?

(A valid answer can also be that I’m using terms like adventure and campaign imprecisely)

## What if I take Necrotic damage more than my hit point total?

In this past weekend’s session (near the end of Lost Mines), my fourth level Warlock took a critical hit from a Wraith.

I have maximum hit points 29, and was currently at 20 HP remaining; the double damage dice rolled as 27 points. As Necrotic damage was explained (I don’t have access to either a Monster Manual or DM’s Guide for 5th Ed.), this cannot be healed in any way prior to a long rest, leaving me with a 2 HP maximum for the remainder of the adventuring day.

It occurred to me to wonder what would have happened if I’d taken a couple more points (the roll of 10d8 would be expected to average 45 points, after all) — leaving me with maximum HP of 0 (since it can’t be negative) until a long rest.

Can a character even benefit from a rest when unconscious due to wounds? If not, would that leave my character in a sort of “limbo” state, where I could only be healed by something I couldn’t actually obtain/do?

## Assigning values to nodes and edges a tree to maximize node whose value is larger than all adjacent edges

A node is valid if its value is greater than all of its adjacent edges.

Task is to maximize the number of valid nodes.

Given $$n$$ values for nodes and $$n-1$$ values for edges, how do I assign these values (to nodes and edges) to a given input tree so the number of valid nodes is maximized?

## Is checking if the length of a C program that can generate a string is less than a given number decidable?

I was given this question:

Komplexity(S) is the length of the smallest C program that generates the string S as an output. Is the question “Komplexity(S) < K” decidable?

With respect to decidability, I only know about the Halting Problem and just learned about Rice’s Theorem while searching online (though I don’t think it can be applied here?). I couldn’t reduce the problem to any undecidable problem I know about. Thanks in advance for any help

## Portable Hole vs Bag of Holding vs Handy Haversack – differences other than size/weight?

I’ve got a kleptomaniac in my group who’s constantly picking up entire armfuls of junk to bring back to town or squirrel away for a rainy day. I want to gift her some kind of carry-all to assist in the junk-holding, but scouring item lists has turned up three different potential options, all of which seem roughly similar other than their respective total volumes.

• Portable Hole has a 3.14 x 10 x 9ft^3 (~270 cubic feet) space with no weight limit
• Bag of Holding has a 3.14 x 1 x 4ft^3 (~12 cubic feet) space with a 500lb weight limit
• Handy Haversack has a combined .75 x 4 x 4ft^3 (~12 cubic feet) space with a combined 120lb weight limit (I think, I am very bad at math)

My intention is to reskin one of the items as a tapestry that’s being used as a cloak by a puma. (Isn’t D&D great?) I want them to be able to put things into the tapestry and also retreive them at will later. Other than that it’s pretty flexible.

Am I overlooking a difference between the Portable Hole, Bag of Holding and Handy Haversack that would make one item significantly better suited to this purpose than the others? If size and weight are the only relevent parameters then it’s an easy enough choice but I can’t help but shake the feeling that I’m missing something.

## Why IDA* Is Faster Than A* But Why IDA* Visit More Nodes That A*?

I used ida* for 8 puzzle and my friends used a* for it too ( with same manhattan distance huristic ).

I calculate average of my algorithm for 20 examples and my friend’s algorithm , The time average for my algorithm was very faster than my friend’s algorithm but mine average nodes that visited is alot more than my friend’s.

I know IDA* visits each node more than once but why it is faster than A* ?

## During a long rest if someone is fully rested, can they keep watch longer than 2 hours?

So I am currently running a game with 3 PCs, 2 of which are Elves and 1 a Human. I am just trying to calculate the most efficient way to run watch shifts during long rests since both of the elves only need 4 hour meditation to be considered fully rested.

In the PHB pg 168 in the section about long rests it states that (emphasis mine):

A long rest is a period of extended downtime, at least 8 hours long, during which a character sleeps or performs light activity: reading, talking, eating, or standing watch for no more than 2 hours.

Now my question is, once a character is considered fully rested and no longer needs the “long rest” are they able to keep effective watch for longer than a period of 2 hours? So say that the elves both finish their 4 hours, can they now keep a vigilant watch for the other 4 hours the human PC needs to rest?

## Do attacks that give the Grappled condition work against creatures more than 1 size larger?

Many creatures, such as the Giant Frog, have attacks that grapple on a hit:

Bite. Melee Weapon Attack: […] Hit: (1d6 + 1) piercing damage. The target is grappled (escape DC 11).

Does this grapple work against a creature Huge or larger? Usual Grapples don’t work if the target is more than one size larger than the grappler.

The target of your grapple must be no more than one size larger than you and must be within your reach.