## Water

BAN USER- 0of 0 votes

AnswersFind the merging point of 2 given link lists...

- Water in United States

I gave him the best O(n) solution i.e by first finding the length of both link list ..........

But he said that he doesn't want an efficient soln. but a soln which is original and cannot be found in any book or over the internet| Report Duplicate | Flag | PURGE

NetApp C

I think this could work if there is a restriction on size of input............

For Ex, if the input is assumed to be only 4 digit long.....Then your method can be modified by now using 2 bit instead of 1 bit for each digit....

2207

(00)(00)(01)(00)(00)(00)(00)(10)(00)(01)

#include <stdio.h>

int findCount(int n,int k)

{

int count=0,sum=0;

int i=1;

int sumk=k*(k-1)/2;

while(i <= n/2)

{

sum=(i*k)+sumk;

if(sum < n)

{

if(n-sum+(i+k-1)<n)

count=count+k;

}

else

break;

i++;

}

return count;

}

int main()

{

int n,k;

scanf("%d",&n);

scanf("%d",&k);

int count=findCount(n,k);

printf("Count = %d\n",count);

return 0;

}

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Thats what I told him.......He said this is the most general solution.

- Water September 18, 2012