## brahmasani99

BAN USER- 1of 1 vote

AnswersA log of wood has n marks on it. Cost of cutting wood at a particular mark is proportional to the length of the log. The log of wood can be cut at all the marks. Find the optimal order of the marks where the log should be cut in order to minimize the total cost of cutting.

- brahmasani99 in India| Report Duplicate | Flag | PURGE

Google Algorithm

int search(int a[],int l,intr,int x)

{

while(l<=r)

{

mid=l+(r-l)/2;

if(a[mid]==x)

retun mid;

else if(a[l]<=a[mid])

{

if(x>a[mid])

l=mid+1;

else if(x>=a[l])

r=mid-1;

else

l=mid+1;

}

else if(x<a[mid])

u=mid-1;

else if(x<=a[r])

l=mid+1;

else

u=mid-1;

}

}

long pow(x,y)

{

if(y==0)

return 1;

if(y==1)'

return x;

int res=pow(x,y/2);

if(x%2==1)

return res*res*x;

return res*res;

}

struct node *clone(struct node *head)

{

HasMap h=new HashMap();

struct node *current1,current2,*prev=NULL,*head2;

for(current1=head;current1;current1=current1->next)

{

temp=malloc(sizeof(struct node));

temp->data=current->data;

if(prev==NULL)

{

head2=temp;

}

else

{

prev->next=temp;

}

h.put(current1,temp);

prev=temp;

h.put(current,temp);

}

for(current1=head,current2=head2;current1;current1=current1->next)

{

current.ptr=h.get(current.ptr);

}

return head2;

}

struct node *clone(struct node *head)

{

HasMap h=new HashMap();

for(current1=head;current1;current=current->next)

{

temp=malloc(sizeof(struct node));

h.put(current,temp);

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

Open Chat in New Window

Hi,

- brahmasani99 March 01, 2014What is point of making the array elements into negative.