# Lane Problem- Infytq 2019 Solve

#### Sample Input:

```A1,A2,A3,A4
B1,B2,B3
C1,C2
D1,D2,D3,D4,D5
10
```

#### Sample Output:

```C3 C4 C5 C6 C7 C8 C9 C10 B4 B5
```

#### Solution: We strongly recommend you to try the problem first before moving to the solution. Python

```# Python code for Lane Problem
# www.codewindow.in

def returnMaxFreeSlotsLane(free_slots):
lane_no = 1
free = free_slots
for i in range(2, 5):
if(free < free_slots[i]):
free = free_slots[i]
lane_no = i
return lane_no

lane = ["T", "A", "B", "C", "D"]
parked_car = []
free_slots = 10 * 
free_slots = 0
for i in range(1, 5):
booked_slots = input().split(",")
if(booked_slots != '-1'):
booked = len(booked_slots)
free_slots[i] = 10 - booked

waiting_cars = int(input())
if(sum(free_slots) < waiting_cars):
print("X")

```

#### JAVA

```/* JAVA solution for Lane problem */
/* www.codewindow.in */

import java.util.ArrayList;

class ParkingSlot {
static int returnMaxFreeSlotLane(int freeSlots[]) {
int laneNo = 1;
int free = freeSlots;
for(int i = 2 ; i <= 4 ; i++) {
if(free < freeSlots[i]) {
free = freeSlots[i];
laneNo = i;
}
}
return laneNo;
}
static int sum(int freeSlots[]) {
int freeSlotsSum = 0;
for(int i = 1 ; i <= 4 ; i++) {
freeSlotsSum += freeSlots[i];
}
return freeSlotsSum;
}
public static void main(String[] args) throws Exception {
int freeSlots [] = { 0, 10, 10, 10, 10 };
String lane[] = { "T", "A", "B", "C", "D" };
ArrayList<String> parkedCar = new ArrayList<>();

for(int i = 1 ; i <= 4 ; i++) {
if(bookedSlots.equals("-1") == false) {
int booked = bookedSlots.length;
freeSlots[i] = (10 - booked);
}
}
if(sum(freeSlots) < waitingCars) {
System.out.println("X");
return;
}

while(waitingCars != 0) {
int laneNo = returnMaxFreeSlotLane(freeSlots);
int booked = 10 - (freeSlots[laneNo]);
while(waitingCars != 0 && booked != 10) {
booked++;
waitingCars -= 1;
}
freeSlots[laneNo] = 10 - booked;
}

for(String booked : parkedCar)
System.out.print(booked+" ");
}
}
```

#### Input:

```A1,A2,A3,A4
B1,B2,B3
C1,C2
D1,D2,D3,D4,D5
10
```

#### Output:

```C3 C4 C5 C6 C7 C8 C9 C10 B4 B5
```