Equilibrium Element in Array in o(n) time complexity ( Interview Question for FAANG companies)

preview_player
Показать описание
Find equilibrium element in array in O(n) time complexity and o(n) space complexity. This is very important question for product based compnies and the FAANG compnies.

Рекомендации по теме
Комментарии
Автор

i have an issue with this question for a long time
now it is solved
thanks sir

yaamraj
Автор

best simple and strightforward solution

hariprasadcr
Автор

thank you for the detailed explanation

rohithbharathi
Автор

Hi Can you please provide optimize solution if we have internal table of positive and negative integers with at least one positive integer, get the maximum possible positive sum

hardikachordia
Автор

Can u please upload code videos on bfs, dfs, prims algo, kruskal algo etc etc also ☺️

devanshprakash
Автор

Please explain Cage- amalgamation graph, how we cane find it?
thanks

Ahadi
Автор

Sir please take class about hypergraph

gamingsparrow
Автор

if the matrix is not balanced then how can I print it

saranvasanth
Автор

Here also we are using two loops. So I think this also n*n time complexity algo.

KNT_
Автор

Here time complexity is O(2n) or O(2^n) which is exponential hence for larger input size it is not approx equals to O(n)

viveksharma
Автор

sir what if there is no equilibirum element

amanahmed
Автор

It is wrong at the step rightsum=sum=0; becuase you have updated the sum in the above steps by using for loop . Then how the rightsum will be equal to zero at first?

banutejagoud
Автор

U must have explained the logic/mathematics behind the for loop

vivekmishra
Автор

int equilibriumPoint(long long a[], int n) {

// Your code here
int left[n];
left[0]=0;
for(int i=1;i<n;i++){
left[i]=a[i-1]+left[i-1];
}
int right[n];
right[n-1]=0;
for(int i=n-2;i>=0;i--){
right[i]=right[i+1]+a[i+1];
}
int result;
for(int i=0;i<n;i++){
if(left[i]==right[i]){
result=i;
}

}
if(result<n){
return result+1;
}
else
return -1;
}
Is this correct way to above problem ??

krishnashejul