π One-stop destination for all your technical interview Preparation π
array: [1,2,3,4]
Here first 3 element: [1,2,3] is arithmetic -> count=1
also next 3 element: [2,3,4] is arithmetic -> count=1
now all together: [1,2,3,4] is arithmetic -> count=1
dp[i] = 1 + dp[i-1]
O(n)
.Previous Questions
p.size()
and check if window == p
.1+2+...+i = N
, then i*(i+1) = 2N => i^2 = N => i = sqrt(N)
k*(k+1)/2 <= n
.Eg :- 1+2+3+...+a = n
Sum of all terms of AP :- (1+a)a/2 = n
n is given to us in question, we have to find a===> a ^ 2 + a = 2 n
===> x ^ 2 + a + 1/4 = 2 n +1/4
===> (a + 1/2 ) ^ 2 = 2n + 1/4
===> (a + 0.5) = sqrt( 2n + 1/4 )
===> a = -0.5 + sqrt( 2n + 1/4 )
a = -0.5 + sqrt( 2\*n + 1/4 )
number > 0
, if its present then we add it in the answer array. if(key < root) -> find in left subtree
else if(key > root) -> find in right subtree
else (key==root) -> delete the node
if leaf node(0 child) -> delete(node) and return NULL
else if node having 1 child -> delete(node) and return the child
else (node having 2 children){
i) find smallest node (leftmost) in the right subtree of the key
ii) copy the smallest node value with key node
iii) delete that smallest node from right subtree (as it have only 1 or 0 child)}
Alternative: In the condition of node having 2 children, we can also find largest node (rightmost) of left subtree of the key.
N
is the number of bits
in the given input numbersith
bit of a number x
is set, we can perform - (x >> i) & 1
.ans = bitset<32>(Xor).count()
ans = __builtin_popcount(Xor);
ans = popcount(Xor) // only since C++20
n & (n - 1)
until xor becomes 0 and increment the count each time.N
for this problem is fixed to 32
. So, strictly speaking, the time complexity of 1st three solutions is O(N) = O(32) = O(1)
. But to differentiate between time complexities of 1st three and last approach, I have denoted them as O(N)
.l >= w
always, w will not be larger than sqrt(area).l = area / w
.