Hello everyone, I am Shouvik Mitra, the founder of wCodes Network. Sorry for being so irregular about this blog. But nevertheless I promise you, my reader, that from today, this blog is going to be my sole partner, and I will regularly keep it updated. With a fresh motto, I would like to introduce the "Daily-Code-a-Challenge" . Hereon, everyday, I will post some exclusively cool questions and challenge you all to complete the task. And for the winners, there is the HALL OF FAME section in our blog. No matter for learners, I promise to post the answers within 24 hours.
CHALLENGE DAY 1
This time you are an Uber driver and you are trying your best to park your car in a parking lot.
Your car has length
carDimensions[0] and width carDimensions[1]. You have already picked your lucky spot (rectangle of the same size as the car with upper left corner at(luckySpot[0], luckySpot[1])) and bottom right corner at (luckySpot[2], luckySpot[3]) and you need to find out if it's possible to park there or not.
It is possible to park your car at a given spot if and only if you can drive through the parking lot without any turns to your lucky spot (for safety reasons, the car can only move in two directions inside the parking lot - forwards or backwards along the long side of the car) starting from some side of the lot. Assume that the car can't drive through or park at any of the occupied spots.
Example
- For
carDimensions = [3, 2],
parkingLot = [
[1, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 1]
],
and
the output should be
luckySpot = [1, 1, 2, 3],the output should be
parkingSpot(carDimensions, parkingLot, luckySpot) = true;
- For
carDimensions = [3, 2],
parkingLot = [
[1, 0, 1, 0, 1, 0],
[1, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 1]
],
and
the output should be
luckySpot = [1, 1, 2, 3],the output should be
parkingSpot(carDimensions, parkingLot, luckySpot) = false;- For
carDimensions = [4, 1],
the sameparkingLotas in the previous example andluckySpot = [0, 3, 3, 3],
the output should beparkingSpot(carDimensions, parkingLot, luckySpot) = true.
- [input] array.integer carDimensionsArray of two positive integers. It is guaranteed that
carDimensions[0] > carDimensions[1]. - [input] array.array.integer parkingLot2-dimensional array, where
parkingLot[x][y]is1if cell(x, y)is occupied and is0otherwise. - [input] array.integer luckySpotArray of four integers - coordinates of your lucky spot at the parking lot (
0 ≤ luckySpot[0] ≤ luckySpot[2] < parkingLot.lengthand0 <= luckySpot[1] <= luckySpot[3] < parkingLot[0].length). It is guaranteed that eitherluckySpot[2] - luckySpot[0] + 1 = carDimensions[0]andluckySpot[3] - luckySpot[1] + 1 = carDimensions[1]orluckySpot[2] - luckySpot[0] + 1 = carDimensions[1]andluckySpot[3] - luckySpot[1] + 1 = carDimensions[0]. - [output] boolean
trueif it is possible to park your car,falseotherwise.
0 comments :
Post a Comment