Saturday, 16 April 2016

Daily-Code-a-Challenge : DAY 1

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
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
luckySpot = [1, 1, 2, 3],
the output should be
parkingSpot(carDimensions, parkingLot, luckySpot) = false;
  • For carDimensions = [4, 1],
    the same parkingLot as in the previous example and
    luckySpot = [0, 3, 3, 3],
    the output should be
    parkingSpot(carDimensions, parkingLot, luckySpot) = true.
  • [input] array.integer carDimensions
    Array of two positive integers. It is guaranteed that carDimensions[0] > carDimensions[1].
  • [input] array.array.integer parkingLot
    2-dimensional array, where parkingLot[x][y] is 1 if cell (x, y) is occupied and is 0 otherwise.
  • [input] array.integer luckySpot
    Array of four integers - coordinates of your lucky spot at the parking lot (0 ≤ luckySpot[0] ≤ luckySpot[2] < parkingLot.length and 0 <= luckySpot[1] <= luckySpot[3] < parkingLot[0].length). It is guaranteed that either luckySpot[2] - luckySpot[0] + 1 = carDimensions[0] and luckySpot[3] - luckySpot[1] + 1 = carDimensions[1] or luckySpot[2] - luckySpot[0] + 1 = carDimensions[1] and luckySpot[3] - luckySpot[1] + 1 = carDimensions[0].
  • [output] boolean
    true if it is possible to park your car, false otherwise.

YOU WILL GET A LINK TO UPLOAD YOUR CODES RIGHT HERE, WITHIN 24 HOURS. KEEP CODING WITH WCODES NETWORK. 

0 comments :

Post a Comment