vijay
BAN USER- 0of 0 votes
AnswerGiven a 3D space with a billion points. Give a million points which are closest (in distance) to a given point.
- vijay in United States| Report Duplicate | Flag | PURGE
int equilibriumElement(int[] array, int N)
{
// Base Case
if(N == 0)
return -1;
long totalSum = 0;
long sumTillNow 0;
for(int i = 0; i< N ; i++)
totalSum += array[i];
if( sumTillNow == totalSum)
return 0;
sumTillNow = array[0];
for(int p = 1; p < N; p++)
{
if( sumTillNow == totalSum - sumTillNow - array[P])
return P;
sumTillNow += array[P];
}
return -1;
}
When current is at the last node, previous is at last but one node, and next will be pointing to null
So,
current -> next = previous; //will point the last node to last but one.
previous = current; //previous is at last node
current = next node; //current is null
next node = current.next(); // Null pointer exception.
Will it be 12? I got 12 in the following manner:
Let's start with a process, say A
Process A
1. Fork()
A(PID =1) and B(PID=0)
2. Fork()&&fork()||fork()
IN the fork() && fork() || fork()
A executes 1st and 2nd forks. It doesn’t execute the 3rd because 1&&1 (since fork() returns 1 for parent process and 0 for child process) results in 1 and hence the 2nd statement of || is not executed. So now we have 2 more child processes of A.
B also executes only two fork() processes as its PID=0 the && will not check the second condition as the 1st fork return 0. Hence it creates 2 more child processes
3. Fork()
So all the 3+3=6 processes execute the 3rd line which results in 12 processes.
Clarify what happens when N ( = # of nodes) is odd.
- vijay July 30, 2016