Question: Uber OA | NSUT | 17 July 2023
0
Entering edit mode

QUESTION 1

Uber HCVs (High Capacity Vehicles) runs across the city of UberLand. UberLand has N stops where the HCVs pickup or drop the passengers. There is a network of M bidirectional roads that connects various stops. Each road has a
particular length attached to it. -The Uber developers have introduced a weird feature of credits where each stop has some assigned credits C[i] (0<=¡<N) which the HCV can collect when it reaches the stop. These credits are used
to travel on a road and number of credits used for travelling on a road is equal to the length of the road. So a HCV can travel on a road if it has credits equal or more than the length of the road.

Input:


Each test case has several lines. The first line contains an integer N which represent the number of stops in UberLand.
The second line contains an array C of N integers which represents credits for each stop.
The third line contains an integer M which represent the number of roads in ÜberLand.
Then the following M lines each contain three integers X (0<=X<N) , Y (0<=Y<N) Z (1<=Z<=100) which means there is road connecting stops X and Y with length Z where X I= Y
Then the last 2 lines contains one integer respectively, S and D which  destination stop D (0<=D<N) with
minimum distance travelled. Since you are a software developer yourself you think of writing a program to calculate the minimum distance that you need to travel or return -1 if there is no way possible. Assume the HCV starts at the source stop S and has credits aqual to the credits of S at the start.


Input :


Each test case has several lines.

  • The first line contains an integer N which represent the number of stops in UberLand.
  • The second line contains an array C of N integers which represents credits for each stop.
  • The third line contains an integer M which represent the number of roads in UberLand.
    Then the following M lines each contain three integers X (0<=X<N) ,Y (0<=Y<N) Z (1<=Z<=100) which means there isroad connecting stops X and Y withlength Z where X I= YThen the last 2 lines contains one
    integer respectively. S and D whichrepresent the source and the destinationstop.

 

 

Constraints

1 <=N<=50
0<=M<=100
0<=C[<=100
1<=Length of each road<=100

 

Example

Input :

5
2 10 5 100 3
8
0 1 2
0 3 5
0 2 1
1 3 10
1 4 15
2 3 7
2 4 90
3 4 80
4


Output

19


Explanation :


.The path is highlighted in red with order

•[execution time limit] 2 seconds
(cpp)
• [memory limiti 1 GB
• [input] integer numOfStops
number of stops
• [input] array.integer credits
credits for each stop
• [input] integer numOfRoads
number of roads
•[input) array.array.integer roads
road details
• [input] integer source



QUESTION 2

The interplanetary portal has been opened, and Earth is now home to sentient creatures from a thousand different planets. As part of the committee maintaining the records of these visitors,
you are tasked with answering any queries the authorities or the media might have concerning our guests. Late one evening, you get a weird request. The Daily Newspaper is writing an article
on "The Average Alien" to enlighten the earth folks about the different cultural and physiological differences between the various species. To this end, you are supposed to answer the following
query with a simple "True" or "False":

 

Does an alien with an average number of legs for an alien residing on Earth actually reside on Earth?


Your assistant has pulled up the relevant data for you (the array an contains the number of legs each alien has) but is nowhere to be found now, so you decide to get your hands dirty and do
the task yourself, lest you be expelled from the committee and neuralyzed immediately. Remember that the "number of legs" can conventionally only be whole number; hence, your
answer must consider that by rounding the average. Consider whether a group of fully formed humanoid creatures will have as many legs distributed amongst them when in a dilemma.

 

Example


Input: [2, 3, 4]
Output: True
Explanation: The average number of legs is 3, which is present in the array

Constraints:


[a] < 10^3
0 <= a, <= 10^7



QUESTION 3

There are n cars standing in a line, a and each car has a price on it C1, C2, C3 ....Cn-
As a Software Engineering Intern, your mentor has assigned you a task. You have to make the car prices non-decreasing as fast as possible. You can perform the following operation on the cars at the X-th chance:
Select some distinct cars, at positions i1, l2, lg,...g (k>=0) which are between 1 and n, and add price 2X-1 to each position of the car. Formally C, = C,+2%-1,
Find the smallest number T such that after T chances you can make the car prices non- decreasing


Example-1: You have four cars having price [1,7,6,5]. If you select indices 3,4 at the 1-st chance and 4 at the 2-nd chance, then prices will become [1,7,7,8). There are some other possible ways
to make car prices non-decreasing in 2 chances, but you can't do it faster.


Example-2: You have two cars having price [6,2]. If you select index 2 at the 1-st chance andselect no cars at 2-nd chance and then select index 4 at the 3-nd chance, then prices will become [6,7]. There are some other possible ways to make car prices non-decreasing in 3
chances, but youcan't do it faster.


You have to answer t independent test cases.
[execution time limit] 0.5 seconds (cpp)
[memory limit] 1 GB
[input] integer t
The first line contains single integer t (1<=t<=104 )
the number of test cases.
[input] array. array. integer64 carPrices
The first line of each test case contains n integers (n>0), C1, C2, C3.....C,, where C, is the
price of i-th car (-105<C;<105). It is guaranteed that the sum of values of n over all test cases in the input does not exceed 106
[output] array.integer64
For each test case, print the minimum number of chances in which you can make car

 

 

ADD COMMENTlink 15 months ago Delta 2.8k
Entering edit mode
0

Please share the solution for graph question...

 

ADD REPLYlink 15 months ago
Dream Big
• 0
0
Entering edit mode

For interplanetary problem : [in python3]

def interplanetary(arr):
    average = round(sum(arr) / len(arr))
    return average in arr
ADD COMMENTlink 15 months ago Pratik Walia • 20

Login before adding your answer.

Similar Posts
Loading Similar Posts