ADP Interview Question for Dev Leads Dev Leads


Country: India




Comment hidden because of low score. Click to expand.
0
of 0 vote

Could you please clarify on condition 1 & 3.
Condition 1 says that ' If the cost of all the items in an order is more than $1000, split those items into multiple packages, otherwise one package would be enough'

Even if items distributed in a different package with each item having cost more than 1000$ than condition 3 can never be satisfied

- Anonymous November 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I will tell an example for suppose a user ordered $2000 worth 3 products with weights 1000g, 500g, and 500g. Now we need to split as per 1st condition so we split into 2 packages with each 1000g. Costs of the products also same 1000, 500 and 500 rupees. Check now each package doesn't have more than 1000 rupees worth products, if package has more than 1000 than you have do divide the package into some other way

- Kittu November 22, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef struct
{
	int cost;
	int weight;
        int couriercharges; //Indicate courier charges for x weight
}item_t;

typedef struct
{
	item_t *items;//List of items
        int        no_of_items;//no. of items in a package
        int        cost; // Total cost of the package
}package_t;

#define MAX_PACKAGES = 100;
typedef 
{
	package_t *packagelist[MAX_PACKAGES];
	int 	   no_of_package;
}packages_t;


packages_t splits_item_package(item_t item[], length)
{
	int no_of_packages = 0;
	int total_no_of_item_packed = 0;
	packages_t *packages;
	package_t  *package;
	packages = (packages_t*) malloc(sizeof(packages_t));
	packages->no_of_packages = 0;
	if (length == 0) return -1;
        //Sort item in the descending order of Costofcourier/weight ratio
        //and store the same in array sortedItem
        // e.g. weight { 500, 200, 700, 100 }
        // cost {310,310,465,310}
        // cost/Weight {0.62, 1.55, 0.66, 3.1}
	// SortedOrder of Items = {100,200,500,700}
	
        
	for( int i =0 ;i<length ;i++)
	{
		packages->packagelist[i] = (package_t*) malloc(sizeof(package_t));
		package = packages->packagelist[i];         	
		package->items = (item_t*) malloc(sizeof(item_t) * length);
		package->no_of_items = 0;
                package->cost = 0
		j = total_no_of_item_packed;
		for(j ;j< length; j++)
		{
			if(package->cost + sortedItems[j] <= 1000)
			{
				index = package->no_of_items;
				package->item[index].cost = sortedItems[j].cost;
				package->item[index].weight = sortedItems[j].weight;
				package->item[index].courierCharges = 	
				sortedItems[j].courierCharges;
				package->cost += sortedItems[j].cost;
				package->no_of_items++;
				total_no_of_item_packed += package->no_of_items;
				no_of_packages++;
			}
			else
			{
				break;		
			}
								
		}
		if(j  == length)
		break;
	}

	packages->no_of_packages = no_of_packages;
	return packages;			
}

- Anonymous November 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This doesn't dividing weights into equally over different packages.

- Kittu November 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes, In the example, i have taken above where
weight { 500, 200, 700, 100 }
Price {150,300,100,800}
Couriercost {310,310,465,310}
In the above example, equal division is not possible, so the result is optimized for courier cost. In the input set which you have taken
weight { 500, 500,1000 }
Price {500,500,1000}
Couriercost {310,310,720}
The equal divison is possible. So, output of the above logic would result in equal divison of weight and optimized courier cost. Please suggest or share some input set.

- Anonymous November 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you explain your algorithm.

- Kittu November 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.concurrency.pkg;

public class OrderSplitting {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int itemPrice[] = { 500, 200, 400, 1000, 2500, 3000 };
		int itemWeight[] = { 200, 800, 300, 700, 800, 200 };
		int totalPrice = 0;
		for (int i = 0; i < itemPrice.length; i++) {
			totalPrice = totalPrice + itemPrice[i];
		}
		int reminder = totalPrice % 1000;
		int totalPackage = totalPrice / 1000;
		if (reminder > 0) {
			totalPackage += 1;
		}
		for (int j = 0; j < itemWeight.length; j++)
			System.out.print(itemWeight[j] / totalPackage + " , ");
	}

}

- Suresh Patel January 03, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More