Messiah
BAN USER- 2of 4 votes
AnswersSuppose u have a square matrix of 0s and 1s only ... find the longest path of 1s available in the matrix and return that .. you can only move right and down ... For e.g.
- Messiah in India
0 0 0 1 1
1 1 1 0 1
0 1 1 1 0
0 0 1 0 0
1 1 1 1 1| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Algorithm
#include<iostream>
using namespace std;
int main()
{
int A[5][5] = {{0,0,0,1,1},{1,1,1,0,1},{0,1,1,1,0},{0,0,1,0,0},{1,1,1,1,1}};
int temp[5][5];
int end_r(0), end_c(0);
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
temp[i][j] = A[i][j];
int top(0), left(0), max(0);
if(i>0) top = temp[i-1][j];
if(j>0) left = temp[i][j-1];
if(top>left) max = top; else max=left;
if(temp[i][j] && max) {temp[i][j] = ++max, end_r=i; end_c=j;}
cout<<temp[i][j]<<" ";
}
cout<<endl;
}
int i = end_r, j = end_c, count=temp[i][j];
--count;
while(count){
if((temp[i-1][j]) == count) --i; else --j;
--count;
}
cout<<"Starting Point"<<" "<<i<<" "<<j<<endl;
cout<<"Ending Point"<<" "<<end_r<<" "<<end_c<<endl;
cout<<"Max Length"<<" "<<temp[end_r][end_c];
return 0;
}
@sonesh What I understand from left most right cousin is that the node that we need to find should not be the child of the parent of the given node, that means in your example above, left most right cousin of 3 is not 4, because siblings are literally not cousins. Cousins mean the nodes at the same level but not the children of the same parent. Hence 9 is a cousin of 5.
- Messiah January 22, 2013Something like this?
SELECT *
FROM EMPLOYEE
LEFT INNER JOIN
(SELECT Dep_Reg.DeptId as Dep_id,
Department .EmpId as Emp_id,
Department .DeptName as Dept_name,
Dep_Reg .RegnName as Regn_name,
Dep_Reg.RegnId as Regn_id
From Region Dep_Reg
LEFT INNER JOIN
Department on Dep_Reg.Dep_id= Department.DepId
GROUP BY Dep_Reg.Dep_id) as EmpData on EMPLOYEE
ON EMPLOYEE.EmpId= EmpData.Emp_id
Where EMPLOYEE.EmpId=""
Somewhat similar to 15290749
- Messiah January 25, 2013