Question: Latest HackerRank OA Coding Questions & Solutions | Server Faults & Modified Knapsack
0
Entering edit mode

Question 1: Faulty Server Replacement

Problem Statement:

Implement a prototype service to automate the detection and replacement of faulty servers to improve the availability of an application.

There are n servers with IDs s1, s2, ..., sn, and an array of strings, logs, of size m. The log format is "<server_id> <success/error>", representing the ID of the server and the status of the processed request. If a particular server ID logs an error for three consecutive requests, it is considered faulty and is replaced with a new server with the same ID.

Given n and the array logs, find the number of times a faulty server was replaced.

Example:

n = 2

logs = ["s1 error", "s1 error", "s2 error", "s1 error", "s1 error", "s2 success"]

Output: 1

Explanation:

  • s1 logs its 1st error.

  • s1 logs its 2nd error.

  • s2 logs its 1st error.

  • s1 logs its 3rd error  Detected, s1 is replaced. (Count = 1)

  • s1 logs its 1st error (since it was replaced, the count resets).

  • s2 logs a success  (s2's error count resets to 0).

Question 2: Madam C.J. Walker (Modified 0-1 Knapsack)

Problem Statement:

Madam C.J. Walker is historically renowned for becoming the first African-American businesswoman in America. One of her business plans involving the sale of cosmetics is a modification of the standard 0-1 knapsack problem.

Walker's business plan begins with an array of n items. She wants to buy products and resell them for profit. The cost of buying the ith item is cost_i, and it earns her a profit of 2^i. She has a total of x amount of money.

Find the maximum profit that can be generated for the given amount of money. As the answer can be rather large, report the answer as maxProfit mod{10^9+7}.

Example:

n = 5, cost = [10, 20, 14, 40, 50], x = 70

A possible optimal combination:

She can buy item 4 (cost 50) and item 2 (cost 14) for a total cost of 64 (<=70).

Her profit will be 2^4 + 2^2 = 16 + 4 = 20.

ADD COMMENTlink 2 hours ago admin 1.8k

Login before adding your answer.

Similar Posts
Loading Similar Posts