In this problem, we are given a number N. Our task is to find the number of divisors of all numbers in the range [1, n].Let’s take an example to understand the problem,Input : N = 7 Output : 1 2 2 3 2 4 2Solution ApproachA simple solution to the problem is by starting from 1 to N and for every number count the number of divisors and print them.Example 1Program to illustrate the working of our solution#include using namespace std; int countDivisor(int N){ int count = 1; for(int i = 2; i
In this problem, we are given a number N which is the size of an array consisting of all zeros and Q queries each of the following type −update(s, e, val ) -> this query will update all elements from s to e (both inclusive) to val.Our task is to find the number of different numbers in the array after applying the given operation q timesLet’s take an example to understand the problem, Input : N = 6, Q = 2 Q1 = update(1, 4, 3) Q2 = update(0, 2, 4) Output : 2ExplanationInitial array, arr[] = {0, 0, ... Read More
In this problem, we are given an array arr[] in which each element represents a pile of boxes (each of unit height). Our task is to find the number of boxes to be removed.The person is standing at index 0 of the array at the height of the pile of boxes and he needs to move to the end of the array. The condition to move from one pile to the next is by jumping to the next.Jump is possible only when the next pile is at the same height or is at height less than it. If the height ... Read More
In this problem, we are given an integer value N.Our task is to Find the nth term of the series −9, 45, 243, 1377, 8019, …Let’s take an example to understand the problem,Input : N = 4 Output : 1377Solution ApproachA simple solution to find the problem is by finding the Nth term using observation technique. On observing the series, we can formulate as follow −(11 + 21)*31 + (12 + 22)*32 + (13 + 23)*33 … + (1n + 2n)*3nExampleProgram to illustrate the working of our solution#include #include using namespace std; long findNthTermSeries(int n){ return ( ( (pow(1, n) + pow(2, n)) )*pow(3, n) ); } int main(){ int n = 4; cout
In this problem, we are given an integer value N. Our task is to find the nth term of the series −0, 8, 64, 216, 512, 1000, 1728, 2744…Let’s take an example to understand the problem, Input: N = 6 Output: 1000Solution ApproachTo find the Nth term of the series, we need to closely observe the series. The series is the cube of even numbers, where the first term is 0.So, the series can be decoded as −[0]3, [2]3, [4]3, [6]3, [8]3, [10]3…For ith term, T1 = [0]3 = [2*(1-1)]3T2 = [2]3 = [2*(2-1)]3T3 = [4]3 = [2*(3-1)]3T4 = [6]3 ... Read More
Z-TransformThe Z-transform is a mathematical tool which is used to convert the difference equations in discrete time domain into the algebraic equations in z-domain.Mathematically, if $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ is a discrete time function, then its Z-transform is defined as, $$\mathrm{\mathit{Z}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{z}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{z^{-\mathit{n}}}}$$Differentiation in z-Domain Property of Z-TransformStatement - The differentiation in z-domain property of Z-transform states that the multiplication by n in time domain corresponds to the differentiation in zdomain. This property is also called the multiplication by n property of Ztransform. Therefore, if$$\mathrm{\mathit{x}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}\mathrm{\left(\mathit{z}\right)};\:\:\mathrm{ROC}\:\mathrm{=}\:\mathit{R}}$$Then, according to the differentiation in z-domain property, $$\mathrm{\mathit{n}\mathit{x}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{-z}\frac{\mathit{d}}{\mathit{dz}}\mathit{X}\mathrm{\left(\mathit{z}\right)};\:\:\mathrm{ROC}\:\mathrm{=}\:\mathit{R}}$$ProofFrom the definition of Z-transform, we have, $$\mathrm{\mathit{Z}\mathrm{\left [\mathit{x}\mathrm{\left(\mathit{n}\right)} \right ]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{z}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{z}^{-\mathit{n}}}$$Differentiating the above ... Read More
In this problem, we are given an integer value N. Our task is to Find the nth term of the given series −0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18, 9, 20, 10… Let’s take an example to understand the problem, Input − N = 6 Output − 2Solution ApproachTo find the Nth term of the series, we need to closely observe the series. It is the mixture of two series and odd and even terms of the series. Let’s see each of them, At even positions −T(2) = 0T(4) ... Read More
Discrete-Time Fourier TransformThe Fourier transform of a discrete-time sequence is known as the discrete-time Fourier transform (DTFT).Mathematically, the discrete-time Fourier transform (DTFT) of a discrete-time sequence $\mathit{x}\mathrm{\left(\mathit{n}\right)}$is defined as −$$\mathrm{\mathit{F}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{\omega }\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{e^{-\mathit{j\omega n}}}}$$Differentiation in Frequency Domain Property of DTFTStatement - The differentiation in frequency domain property of discrete-time Fourier transform states that the multiplication of a discrete-time sequence $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ by n is equivalent to the differentiation of its discrete-time Fourier transform in frequency domain. Therefore, if, $$\mathrm{\mathit{x}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{FT}}{\leftrightarrow}\mathit{X}\mathrm{\left(\mathit{\omega }\right)}}$$Then$$\mathrm{\mathit{n}\mathit{x}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{FT}}{\leftrightarrow}\mathit{j}\frac{\mathit{d}}{\mathit{d\omega }}\mathit{X}\mathrm{\left(\mathit{\omega }\right)}}$$ProofFrom the definition of DTFT, we have, $$\mathrm{\mathit{F}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{\omega }\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{e^{-\mathit{j\omega n}}}}$$Differentiating both sides with respect to ω, we get, $$\mathrm{\frac{\mathit{d}}{\mathit{d\omega }}\mathit{X}\mathrm{\left(\mathit{\omega }\right)}\:\mathrm{=}\:\frac{\mathit{d}}{\mathit{d\omega}}\mathrm{\left[\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{e^{-\mathit{j\omega n}}} ... Read More
Z-TransformThe Z-transform is a mathematical tool which is used to convert the difference equations in discrete time domain into the algebraic equations in z-domain.Mathematically, if $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ is a discrete time function, then its Z-transform is defined as, $$\mathrm{\mathit{Z}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{z}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{z^{-\mathit{n}}}}$$Correlation Property of Z-TransformStatement - The correlation property of Z-transform states that if, $$\mathrm{\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}_{\mathrm{1}}\mathrm{\left(\mathit{z}\right)}\:\mathrm{and}\:\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}_{\mathrm{2}}\mathrm{\left(\mathit{z}\right)}}$$Then$$\mathrm{\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}_{\mathrm{1}}\mathrm{\left(\mathit{z}\right)}\mathit{X}_{\mathrm{2}}\mathrm{\left(\mathit{z}^{-\mathrm{1}}\right)}}$$Where$$\mathrm{\mathit{R}_{\mathrm{12}}\mathrm{\left ( \mathit{n} \right )}\:\mathrm{=}\:\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}}$$ProofFrom the definition of Z-transform, we have, $$\mathrm{\mathit{Z}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{z}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{z^{-\mathit{n}}}}$$$$\mathrm{\mathit{\therefore \mathit{Z}\mathrm{\left[ \mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\right ]}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathrm{\left[ \mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\right ]}\mathit{z}^{-n}}\:\:\:\:\:\:...(1)}$$The correlation of two signals is defined as, $$\mathrm{\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\:\mathrm{=}\:\sum_{\mathit{k=-\infty}}^{\infty}\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{k}\right)}\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{k-n}\right)}\:\mathrm{=}\:\sum_{\mathit{k=-\infty}}^{\infty}\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{k-n}\right)}\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{k}\right)}\:\:\:\:\:\:...(2)}$$Therefore, from eqns.(1)&(2), we get, $$\mathrm{\mathit{Z}\mathrm{\left[\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)} \right ]}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}}\mathrm{\left[\sum_{\mathit{k=-\infty}}^{\infty}\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{k}\right)}\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{k-n}\right)} \right ]}\mathit{z}^{-n}$$Rearranging the order of summations, we get, $$\mathrm{\mathit{Z}\mathrm{\left[\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\otimes \mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)} \right ]}\:\mathrm{=}\:\sum_{\mathit{k=-\infty}}^{\infty}\:\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{k}\right)}\mathrm{\left[\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{k-n}\right)}\mathit{z}^{-n} ... Read More
Z-TransformThe Z-transform is a mathematical tool which is used to convert the difference equations in discrete time domain into the algebraic equations in z-domain.Mathematically, if $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ is a discrete time function, then its Z-transform is defined as, $$\mathrm{\mathit{Z}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{z}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{z^{-\mathit{n}}}}$$Convolution in Time Domain Property of Z-TransformStatement - The convolution in time domain property of Z-transform states that the Z-transform of the convolution of two discrete time sequences is equal to the multiplication of their Z-transforms. Therefore, if, $$\mathrm{\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}_{\mathrm{1}}\mathrm{\left(\mathit{z}\right)};\:\:\mathrm{ROC}\:\mathrm{=}\:\mathit{R}_{1}}$$$$\mathrm{\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}_{\mathrm{2}}\mathrm{\left(\mathit{z}\right)};\:\:\mathrm{ROC}\:\mathrm{=}\:\mathit{R}_{2}}$$Then, according to the convolution property, $$\mathrm{\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}*\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{ZT}}{\leftrightarrow}\mathit{X}_{\mathrm{1}}\mathrm{\left(\mathit{z}\right)}\mathit{X}_{\mathrm{2}}\mathrm{\left(\mathit{z}\right)};\:\:\mathrm{ROC}\:\mathrm{=}\:\mathit{R}_{\mathrm{1}}\cap\mathit{R}_{\mathrm{2}} }$$ProofThe convolution of two sequences is defined as, $$\mathrm{\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{n}\right)}*\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n}\right)}\:\mathrm{=}\:\sum_{\mathit{k=-\infty}}^{\infty}\mathit{x}_{\mathrm{1}}\mathrm{\left(\mathit{k}\right)}\mathit{x}_{\mathrm{2}}\mathrm{\left(\mathit{n-k}\right)}}$$Now, from the definition of Z-transform, we have, $$\mathrm{\mathit{Z}\mathrm{\left [\mathit{x}\mathrm{\left(\mathit{n}\right)} ... Read More