New answers tagged

-1

Hii here is my approach using C++. You can follow it along with the comments. int solution(vector<int> &A){ int count = 0; //First checking if we can cut zero or not if(A[1]-A[0] > 0 && A[2]-A[1] > 0){ count++; } if(A[1]-A[0] < 0 && A[2]-A[1] < 0){ count++; } //Checking if we can cut from first till last for(...


3

I'm assuming that you're on a RAM machine with word size $\Theta(\log N$). Keep a van Emde Boas tree $T$ storing the empty positions (integers from $1$ to $N$). Whenever you insert an element $i$, delete $i$ from $T$ (in $O(\log \log N$) time) and set NEXT to the minimum element in $T$ (in $O(1)$ time). Whenever you delete an element $i$, insert $i$ to $T$ ...


1

In full generality (no/little compatibility restrictions), this means you have to explore all possible combinations. The time to do that will be huge if there are many classes of components with many alternatives each.Your best bet is to order the component classes in some way, and then use a backtracking type search to explore the alternatives. It doesn't ...


Top 50 recent answers are included