Cadence Inc Interview Question
Development Support EngineersCountry: India
Interview Type: In-Person
I wrote the following code and took n=5 and k=3. But it doesnt work. Can someone help me out please
#include <bits/stdc++.h>
using namespace std;
int main() {
int n=5;
int arr[5][5];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>arr[i][j];
}
}
int k=3;
int sum=0, ans=INT_MAX, count=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-k;j++)
{
while(count<k && arr[i][j+count]==1)
{
sum=sum+ pow((n/2-i),2)+ pow((n/2-j-count),2);
count++;
}
if(sum<ans && sum!=0)
ans=sum;
sum=0;
count=0;
}
}
cout<<ans<<endl;
return 0;
}
Can anyone explain the problem? What is the meaning of k contiguous row-wise elements?
- ashu1.220791 October 04, 2015