← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Here is the full interview question "Server Stress Scoring - Stripe OA Interview | ShowOffer" from Stripe on ShowOffer.io:
Server Stress Scoring - Stripe OA Interview | ShowOffer
You are given a list of servers, each with a stress score. The stress score is an integer representing the current stress level of the server. Your task is to calculate the total stress score for each server, taking into account the stress levels of its neighbors.
Input:
servers, where servers[i] represents the stress level of the server at index i.k, representing the number of neighbors to consider on each side of a server.Output:
Constraints:
1 <= len(servers) <= 10^50 <= k < len(servers)Examples:
Input:
servers = [1, 2, 3, 4, 5]k = 1neighbors = [1, 1, 2, 2, 1]weights = [0.5, 1.0]threshold = 10Output:
[1.0, 2.5, 5.5, 6.5, 5.0]Explanation:
Input:
servers = [10, 20, 30, 40, 50]k = 2neighbors = [2, 2, 3, 3, 2]weights = [0.5, 0.5, 1.0]threshold = 15Output:
[10.0, 25.0, 40.0, 50.0, 60.0]Explanation:
Hints:
Solution:
def server_stress_scoring(servers, k, neighbors, weights, threshold):
n = len(servers)
stress_scores = [0] * n
for i in range(n):
total_stress = servers[i]
current_weight = 1.0
for j in range(1, neighbors[i] + 1):
if i - j >= 0:
total_stress += servers[i - j] * weights[j - 1]
current_weight += weights[j - 1]
if i + j <