0 like 0 dislike
540 views

Can someone Help with First , I tried Implementing dikstra but was not able to code it on time.

A fireman is trying to save a person from a burning building. The fireman must navigate through connected rooms to get to one of the exits. Each room has a risk factor associated with it, your task is to help the fireman find the exit route with the least risk.
The risk is calculated as the distance from a given start room to an exit added to the severity level of fire in the rooms used to exit the building.
Given that there is only one minimum risk route, write a function that given a string array of rooms A, another string array B such that B[i] contains a string of comma-separated rooms accessible from room A[i], and another array of integers C such that C[i] indicates the severity of fire (higher number shows the situation is more severe) in room A[i], returns a comma-separated string of rooms in the minimum risk route according to their order from the start to the last room before exit. The fireman starting room is always A[0] and
"E" always indicates an exit. You can assume every room has a distance of 1.
If there is no route to the exit, return an empty String.

Examples

1.

A = ["S", "A", "B", "C"]
B = ["A,B", "C", "E", '']
C= [0, 3, 4, 6]
Explanation of the Input: From "S" you can go to "A" or "B", and the fire severity in S is 0. From "A" you can go to "C" and the fire severity in "A" and "C" is 3 and 6 respectively. "C" does not lead to any room. From "B" you can go to "E" which is the exit and the severity in B is 4.
Output: "S,B"
Explanation: The only route to Exit "E" is S->B with a Risk of 6 (4 in room B + 2 for distance visiting room B and to the exit).

2.

A = ["S", "A", "В", "С"]
B = ["A,B", "C", "E", "E"]
C= [0, 1, 4, 1]
Output: "S,A,C"
Explanation: We have 2 possible routes to Exit "E" S->B and S->A->C, but S->A->C has less risk of 5 compared to S->B with 6

3.

A = ["S", "A", "B", "C", "D", "F"]
B = ["A,B", "C,D", "E", "E", "F", "E"].
C= [0, 1, 14, 7, 1, 1]
Output: "S,A,D,F"
Explanation: S->A->D->F has a minimum risk of 7

Write a function solution that, given an array A of N integers (between -100 and 100), returns the sign (-1, 0, 1) of the product of all the numbers in the array multiplied together.
Assume that N is between 1 and 1000.
For example, given A = [1, -2, -3, 5], the function should return 1 (the multiplication equals
30).
Given A = [1, 2, 3, -5] your function should return - 1 (the multiplication equals -30).
Given A = [1, 2, 0, -5] your function should return 0 (the multiplication equals 0).

Ben is getting bored every day when he drives to work and back home. Thus, to make this journey a bit more fun, he was measuring the times spent between traffic lights and he was measuring the interval traffic lights turn red from green and turn green from red. He noticed red and green lights generally last the same time, if green is on for a minute for the same light, red also takes a minute.
Given the time spent on each road between lights and given the period a green/red light lasts in each traffic light, determine how long it will take for Ben to go home.
Please consider all traffic lights just turn red and he just started the engine and ready to hit the road.
Write a function:
class Solution ‹ public int solution(intll A, intll B); ›
that, given a zero-indexed array A consisting of N integers and a zero-indexed array B consisting of K integers, returns an integer that indicates the total journey duration of Ben.
Example:
A: [240, 800, 100], A is the time spent before the next light. A always has one more element than B because, after the last light, he drives a bit more and reaches home.
B: [60, 120], BO is showing the first traffic light will be red for the first 60 seconds from the journey starts, then it will be green for 60 seconds and red for 60 seconds, and so on.
Expected output: 1200
It will take 240 seconds for Ben to arrive at the first light, the light will just turn red and Ben will wait for the light for 60 seconds. Ben will move on from that light at 300 seconds of his journey, Ben will move on with the road that will take 800 seconds. When Ben arrived at the second traffic light after 1100 seconds his journey started, he will have a green light there and will go on without stopping. He will be home driving on the remaining road for 100 more seconds.

| 540 views