Blog. About everything

Can you find a price of a old car?

This was the code test to find your analytic skills and C# knowledge for interview process. In addition to those skills, it also tests your skills for .Net, Jquery, Ajax, Deployment process and most importantly your ability to perform complex algorithm.
Write a working program which should do the following:

You are tasked with writing an algorithm that determines the value of a used car, given several factors.

AGE: Given the number of months of how old the car is, reduce its value one-half (0.5) percent. After 10 years, it's value cannot be reduced further by age. This is not cumulative.

MILES: For every 1,000 miles on the car, reduce its value by one-fifth of a percent (0.2). Do not consider remaining miles. After 150,000 miles, it's value cannot be reduced further by miles.

PREVIOUS OWNER: If the car has had more than 2 previous owners, reduce its value by twenty-five (25) percent. If the car has had no previous owners, add ten (10) percent of the FINAL car value at the end.

COLLISION: For every reported collision the car has been in, remove two (2) percent of it's value up to five (5) collisions.

Each factor should be off of the result of the previous value in the order of

  1. AGE
  2. MILES
  3. PREVIOUS OWNER
  4. COLLISION

E.g., Start with the current value of the car, then adjust for age, take that result then adjust for miles, then collision, and finally previous owner. Note that if previous owner, had a positive effect, then it should be applied AFTER step 4. If a negative effect, then BEFORE step 4.

AssertCarValue(decimal expectValue, decimal purchaseValue, int ageInMonths, int numberOfMiles, int numberOfPreviousOwners, int numberOfCollisions)

Some Sample Test Data
AssertCarValue(25313.40m, 35000m, 3 * 12, 50000, 1, 1);
AssertCarValue(19688.20m, 35000m, 3 * 12, 150000, 1, 1);

You can visit it at http://alkesh-patel.com/CarCalculator/ to test the solution and also see the code by going to "View Code On Github" link on that page.

How about writing a program for you knowledge of Programming?

This was the code test provided to me by one of the company during interview process. It tests your skills for .Net, C#, AngularJs, Bootstrap, Jquery, Ajax, SQL and most importantly your ability to perform complex algorithm.
Write a working program which should do the following:

  1. Given a category id return category name, parentCategoryId and key-word. Ensure that if key-word is not present for the category, then the data from its parent should be returned.
    Sample Input/Output:
    • Input:201; Output: ParentCategoryID=200, Name=Computer,Keywords=Teaching
    • Input: 202; Output: ParentCategoryID=201, Name=Operating System,
  2. Given category level as parameter (say N) return the names of the categories which are of N’th level in the hierarchy (categories with parentId -1 are at 1st level).
    Sample Input/Output:
    • Input: 2; Output: 101, 102, 201
    • Input: 3; Output: 103, 109, 202

I responded with a live solution which can be tested. You can visit it at http://www.alkesh-patel.com/fullstack and also see the code by going to "Go to Code" link on that page.