Single Lane Highway | Codevita 9 SOLUTIONS

Single Lane Highway Codevita 9 Solution

Problem Description

Certain number of vehicles are passing a solitary path street. Rates of all vehicles change. It is anything but difficult to see, that relying upon the paces of the vehicles different gatherings will be shaped. 

Being a solitary path street passing/surpassing isn’t permitted. Given paces of vehicles, compute what number of gatherings can be framed if all potential stages are considered. Allude example1 for better understanding. 

Print number of gatherings isolated by the quantity of changes. 

 

Imperatives 

0 <= N < 10 ^ 5 

0 <= speed of individual vehicle < 10 ^ 9 

 

Information 

First line contains a whole number N, which indicates the quantity of vehicles 

Second line contains N space isolated whole numbers which indicates the speed of individual vehicle. 

 

Yield 

Print number of gatherings partitioned by the quantity of stages adjusted upto 6 decimal spots. 

 

Time Limit 

 

Models 

Model 1 

 

Info 

10 20 30 

 

Yield 

1.833333 

 

Clarification: 

So all potential changes are: 

{10 20 30} 

{10 30 20} 

{20} {10 30} 

{20 30} {10} 

{30} {10 20} 

{30 20} {10} 

 

So here there are all out 6 changes, and complete number of gatherings are 11. 

In this way, yield is 11/6 = 1.833333 

 

Model 2 

Info 

56 78 13 92 

 

Yield 

2.083333 

 

Clarification: 

So here there are all out 24 changes, 

 

For instance: 

{56 78 13 92} 

{92} {13 78 56} 

{56} {13 92 78} 

{78 92} {13 56} 

Et cetera. The all out number of gatherings are 50. 

Thus, the yield is 50/24 = 2.083333

Related:

Codevita Season 9 All Questions Solutions

Listed Here :

Leave a Comment

close
error: Content is protected !!