System Design Interview Question: DESIGN A PARKING LOT - asked at Google, Facebook

Ғылым және технология

In-depth system discussion of a popular coding interview question, chapters:
0:32 Problem statement
0:55 Finding a solution
2:43 Questions to ask
6:35 Object oriented design/class hierarchy
13:57 Coding question approach
23:34 Testing
This system design interview question/how to system design is for software engineers, software developers, web developers, front end engineers, QA engineers, product managers, network engineers equally important. This interview problem can be asked as a coding interview question, system design question or object oriented design question.
SiT website: www.successintech.com
Facebook: SuccessInTech/
Twitter: successintech
Other names for this problem are: Amazon Locker interview question, The Parking Lot interview question, Parking Lot using OO techniques, Object oriented parking lot.
Music: www.bensound.com

Пікірлер: 486

  • @SuccessinTech
    @SuccessinTech6 жыл бұрын

    I'm doing a little experiment over on IGTV, the SiT VLOG. Check it out! instagram.com/tv/BkYf4GphfQz/

  • @TrulyLordOfNothing
    @TrulyLordOfNothing3 жыл бұрын

    You're receiving lots of feedback that your approach is not ideal. Nevertheless, I thank you for putting it up. First, newbies have no idea how to start and at least you helped them make a start. Second, your video has provoked this great discussion. So, thanks!

  • @Blingblingblingling
    @Blingblingblingling6 жыл бұрын

    one thing missing in the design that is probably important in all parking lots is time, since parking charge is usually foremost determined by how long the vehicle is parked

  • @vinodreddy
    @vinodreddy5 жыл бұрын

    It's awesome that you covered a part of system design, oop and ds & algos in single video. We can show interviewer that we are good with 3 concepts. That's cool.

  • @ajaygaur3392
    @ajaygaur33925 жыл бұрын

    In Uber interview, I got into DSA part straight away and I thought I was able to build pretty optimised system design but neither did I ask any questions at the start nor I allowed interviewer to speak 😅. Learnt my lesson, take a step back

  • @genuineprofile6400

    @genuineprofile6400

    Жыл бұрын

    Requirement gathering is key for system design interviews.

  • @blim2020
    @blim20203 жыл бұрын

    Ramon, Thank you. I am not an engineer, I am a UX designer, however, found this incredibly helpful to see a different perspective with colleagues I will be working with, and getting an idea of how others see the "big picture". This was eye-opening.

  • @sergeyzelvenskiy3925
    @sergeyzelvenskiy39255 жыл бұрын

    I disagree with this process. Why design the class hierarchy before we discussed the functionality? Why collect color and how it was used? Why have different classes for the different sizes of the car if there is no difference in behavior? Why placeVehicle is a part of ParkingLot class, while removeVehicle is a part of Spot class? It would be confusing if I would have to support this code. The code is not actually done. The mentions of stack and hashmap are pretty vague. It's not clear how exactly this implementation will be working. Honestly, if I would be the interviewer and just see this, I would not give the high grade.

  • @SuccessinTech

    @SuccessinTech

    5 жыл бұрын

    Cool, thanks for the feedback!

  • @sergeyzelvenskiy3925

    @sergeyzelvenskiy3925

    5 жыл бұрын

    Welcome. Sorry if I'm a bit too critical, but this is my preception.

  • @damnoish

    @damnoish

    4 жыл бұрын

    removeVehicle is not a method of Spot. It returns a Spot.

  • @mrkevinlui

    @mrkevinlui

    4 жыл бұрын

    It’s not even clear what the “manage parking lot” requirements are.

  • @taylor_o

    @taylor_o

    4 жыл бұрын

    First thing I wondered... who are we designing for? Are we designing a plan for engineers to build? A recommendation system to direct users to their spot? A record keeping system to help the owner make business decisions?

  • @eldojoseph8718
    @eldojoseph87186 жыл бұрын

    This is the best explanation for this interview question I have seen so far. Thanks a lot. Please keep doing more system design questions

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    Glad I could help you, check out my other videos as well! There are more interview questions but also topics like 'What happens after the interview?'.

  • @randomvideos007
    @randomvideos0076 жыл бұрын

    This guy looks (which he is) very very clear in his thought and very organized.

  • @hiteshreddym
    @hiteshreddym6 жыл бұрын

    PriorityQueue will be a better Data Structure to use instead of a stack. We can set the priority based on the natural order(ascending order), which means when a lookup for an empty spot is requested, it always returns the nearest spot. Next, a HashMap can be a better choice. Another choice can be, HashMap where the Integer can be the count. Every time a parking spot is allocated to a vehicle, decrease the count. ex: map.put(L, 5), which means there are 5 spots for the 'L' type vehicle. count 0 means, there is no spot for a vehicle to allot. There are just good designs and bad designs which heavily depend on the use case. We can always impress an interviewer, by bringing up more options and explaining why we are choosing the particular approach, and it's advantages. Anyhow, this video is very useful to frame an approach and move forward with the design and algorithm.

  • @nikhilneela

    @nikhilneela

    5 жыл бұрын

    Nice idea, In the hashmap which maintains the counts of the free spots, how would the system identify the spot. Is it like, the hashmap is used to only check the availability and then get them from a set of arraylists/queue which maintain the free slots for each slot size ? ArrayList smallAvailableSlots, ArrayList large AvailableSlots HashMap hashmap; int count = hashmap.get(SmallParkingSlot); if (count > 0) { ParkingSlot ps = smallAvailableSlots.first(); //update hashmap and arraylist return ps; }

  • @himanshupoddar1395

    @himanshupoddar1395

    4 жыл бұрын

    I don't understand one thing suppose we use a database(say mysql) then why do we even need data structures, can't we just query from it and achieve our goals. Someone please specify!!!

  • @SergeyLeschinsky
    @SergeyLeschinsky4 жыл бұрын

    There are more sense to start classifying spots: compact, standard, ev, disabilities. If you want to keep your design, in my mind more sense in queue than in stack - some spots will never be used, that will increase loading some parts of the lot than others. PS: Thank you for your videos!

  • @Musa_Supreme
    @Musa_Supreme2 жыл бұрын

    Great video. Heres what I got: When asked a question, my answer should start with clarifying questions. Only when having some clarification to a general ask, should i begin implementing such a system. Outside of that specifics about designing the system including OOP classes, properties, and methods are relatively arbitrary. What would have been immensely helpful is identifying components of the system as they relate to specific design patterns ie Singleton, Facade, Observer, etc.

  • @Roycocup
    @Roycocup Жыл бұрын

    See this is very intuitive and makes a lot of sense. And this is also the reason why most people does not understand agile. In agile, the best thing to do is just start by building and getting a quick feedback from the interviewer stating this was not what he wants.

  • @joh1121
    @joh11216 жыл бұрын

    I wish all my teachers were so organized and easy to hear

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +JO H Haha favorite comment so far! Thank you

  • @rahulagrawal3611

    @rahulagrawal3611

    5 жыл бұрын

    If teachers are good we won't lean to learn on our won. Time passed, no point in pointing them. Start learning yourself. No offence. I too have same wish btw.

  • @vinoddiwan5792

    @vinoddiwan5792

    4 жыл бұрын

    At least they must inspire and guide us

  • @EmadGohari
    @EmadGohari3 жыл бұрын

    Thanks for your content and effort, I think this approach is more appropriate for a object oriented design question. Not much discussion is done on the system and its scalability, handling of data, etc. But thank you for the good ideas about implementation side of things!

  • @priyak1333
    @priyak13335 жыл бұрын

    Thanks a lot! This was a really good explanation for this question.

  • @GauravJain108
    @GauravJain1084 жыл бұрын

    One of the best technical videos watched till date.

  • @fengwang2091
    @fengwang20915 жыл бұрын

    This is definitely an awesome explanation. While I always feel in bay area, high tech company cares more about communication skills rather than real technical experience. Even though interviewee can give expected answers for such questions, it is still highly possible in the end they deliver a low availability, low performance, non extensible system. Anyway, it's just some of my concerns. Huge thanks, subscribed already!

  • @popionlyone

    @popionlyone

    4 жыл бұрын

    有意思

  • @AnakarParida
    @AnakarParida6 жыл бұрын

    Hey nice video and I really liked the first part of video where you removed ambiguity and systematic approach. However I have a different approach(not so different) for vehicle parking and unparking. Use a Map unoccupiedSpaces Map occupiedSpaces I am using a List for unoccupied space because it doesn't really matter if I use Stack or List. Actually when we free a vehicle we generally give spot Id to the method. You never mentioned about the Spot class. I believe it should also have something timeIn, timeOut and Vehicle instance. Let me know if am wrong in understanding.

  • @borisschwartz7498
    @borisschwartz74984 жыл бұрын

    Regarding the system design, I would consider to begin with ERD model first and only then move to a class/methods/, coding

  • @quirkyquester
    @quirkyquester2 ай бұрын

    Amazing video! I love this, love how it’s possible to cover all three topics in one design, and allow the interviewer to lead the direction! Thank you!

  • @ericgu1147
    @ericgu11476 жыл бұрын

    Another more modern approach is to favor composition over inheritance. Composition favors the simple function of parking over predicting a taxonomy of classes very early. What if the parking lot starts as a open space for motor vehicles but requirement changes into a parking lot for bicycles and airplanes, or spaceships (things that may not have license plate or conform to parent class). Would the interviewer trash this application/system and start over again? Inheritance encourages future prediction and is not flexible. This happens all the time in the real world.

  • @johnsmith-tc7nl

    @johnsmith-tc7nl

    5 жыл бұрын

    I was with you with Bicycles and airplanes. But dude SPACESHIPS :D. ..... Just kidding. I also favor composition over inheritance. nobody wants to find themselves in the Gorilla in the jungle problem.

  • @learnwithraye3549

    @learnwithraye3549

    5 жыл бұрын

    I agree with you on this. Can you please provide me with links to articles you have read which talks more about this approach?

  • @benleung6331

    @benleung6331

    4 жыл бұрын

    @Eric Gu can you give us an example of composition can be used in place of inheritance for the objects that can be placed in a parking lot system in this exercise? Thanks

  • @josefarias111

    @josefarias111

    4 жыл бұрын

    @Eric Gu IDK man, i can see the whole bicycle's not having a license plate, but airplanes and spaceships would definitely conform to it. As i'd assume that spaceships would be treated similarly to airplanes in the FAAs eyes and Airplanes have a n-number/unique identification number which is used by ATC towers/Pilots for communication to avoid potentially disastrous situations as well as for ownership purposes.

  • @hfontanez98

    @hfontanez98

    3 жыл бұрын

    I would not call it a modern approach. I learned this in college nearly 20 years ago. The problem is that it was either not emphasized or people quickly ignore it after graduating.

  • @kaarthikchinni
    @kaarthikchinni6 жыл бұрын

    Awesome... Really soon thankful for the video. Great job. Keep adding more questions.

  • @pattadar
    @pattadar5 жыл бұрын

    Thanks for the video. You would have added the boundary check for the type of parking lot like PH/Carpool/Regular in the first half session to make more sense of parking lot system design.

  • @dipenpatel5226
    @dipenpatel52266 жыл бұрын

    Great video, I'd love to see more of them. :)

  • @emmanueligbodudu2984
    @emmanueligbodudu29845 жыл бұрын

    Subscribed!! Your Videos are really high quality. Thanks for taking time to share your knowledge

  • @aquatsr
    @aquatsr5 жыл бұрын

    Technically unless you're moving the "spot" around in memory, you don't need the four stacks. Simply keep a counter of all the spots of each type and increment and decrement the counters as you use and clear spots. You can still use the hashMap to store the Spot instances.

  • @SuccessinTech

    @SuccessinTech

    5 жыл бұрын

    Agree!

  • @dkv112233
    @dkv1122336 жыл бұрын

    Would have helped if you could've talked about multiple entrances and hence concurrency?

  • @mandavasairaghavendradines6582
    @mandavasairaghavendradines65824 жыл бұрын

    Thank you, that's a very nice explaination..

  • @alex-as-is
    @alex-as-is5 жыл бұрын

    Thank you so much for the video!

  • @sanathana-sakthi
    @sanathana-sakthi4 жыл бұрын

    Excellent approach on solving complex problem with little baby steps.

  • @vigneshwarmohanraj1490
    @vigneshwarmohanraj14905 жыл бұрын

    Well explained !! Gracias to you

  • @deeptigaur
    @deeptigaur5 жыл бұрын

    Such knowledgeable content. Super thanks for sharing!

  • @leonidp2684
    @leonidp26846 жыл бұрын

    Thank you for great lesson! One thing I missed is regarding the system itself - why you need to subclass Vehicle and how do you address type/size variance?

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    Thank you! There are many different ways to design this. If you expect varieties of vehicles inheritance makes sense (you can do type comparison etc) and in the subclasses you can hide things like shape, size, weight etc. If it‘s only one dimension you care about maybe inheritance is overkill and you could get by with some enums

  • @2307Leito
    @2307Leito6 жыл бұрын

    Dude what a good video, thank you!

  • @vedkumar5690
    @vedkumar56906 жыл бұрын

    you are helping a lot of people , thank you

  • @cyrusmaddy1
    @cyrusmaddy12 жыл бұрын

    You are a lifesaver. Thanks!

  • @rongrongmiao4638
    @rongrongmiao46384 жыл бұрын

    I would use a Queue to track the empty spots.

  • @cynthiamora6761
    @cynthiamora67615 жыл бұрын

    I have an interview with Amazon in about 3 hours.......oh my goodness.....Thank you for this.

  • @Maru-ge6jn

    @Maru-ge6jn

    5 жыл бұрын

    And how did it go?

  • @narendrachouhan5691
    @narendrachouhan56916 жыл бұрын

    best explanation on the internet for this question. please make videos on elevator design, vending machine design and atm design.

  • @darod6098

    @darod6098

    5 жыл бұрын

    Yes please!

  • @anindya7911
    @anindya79116 жыл бұрын

    Nice video and explanation. Thank you and keep uploading

  • @skiyman
    @skiyman5 жыл бұрын

    Thanks for the example. But this is answered as a coding design question. I would go about this in a complete different way. Perhaps approach it top down and not rather jump into technical details right away. Just a few thoughts... 1) Write topdown (guess & confirm) nouns, verbs, entities that apply to this example before drilling down( see below) 2) Draw (guess) a diagram of a typical end to end use case scenario for main nouns to derive events that are triggered 3) Discuss which modules could be developed as stand-alone (or is it a monolithic app) 4) Mention a few future features not included in the plan (e.g. maintenance, reservations, emergency, ) 5) ONLY THEN ask where we should drill down to so a detailed technical coding design 1) Static Nouns (entities) - and a bit of attributes (id keys) Customers, (paying customer, balance management, status) Vehicles (license, CustomerID, status), CustomerPayments (CustomerID, VehicleID, status) CompanyInfo, CompanyInvoices, CompanyReceipts, ParkingLots( companyID ), ParkingLotAccess (entries, exits, ) ParkingSpots (type, status, class, ParkingLotID), ParkingPrices ( Parkingclass, PriceperHour, validity) ParkingPaymentLocations 2) Dynamic Nouns (aggregating historically) VehicleParks (vehicle in ParkingSpot) Reservations (Customer) - future feature perhaps to show how to extend the system 3) Verbs (methods, actions) - very partial list :-) AllocateSpot(vehicle), ReleaseSpot, RegisterVehicle, FreezeVehicle, ReleaseVehicle, BlackListVehicle, ReserveSpot, BillSpot, CollectPayment,

  • @SuccessinTech

    @SuccessinTech

    5 жыл бұрын

    Yeah this can be a very high level system design question too! Very important to interact closely with the interviewer to find out what she/he is trying to probe you for.

  • @rewapatilokendra6291
    @rewapatilokendra62916 жыл бұрын

    perfect view of a parking system, keep doing this...Appreciated. Thank you so much

  • @RahulGupta-sy7bq
    @RahulGupta-sy7bq6 жыл бұрын

    Thanks,it was really helpful..!!

  • @arunparthasarathy
    @arunparthasarathy6 жыл бұрын

    Nicely explained! Very helpful

  • @edvansousa1270
    @edvansousa12706 жыл бұрын

    thanks! great explanation and good ideias.

  • @amartyabhattacharya4945
    @amartyabhattacharya49455 жыл бұрын

    Great Video, Keep the good work up!

  • @chaitu10552
    @chaitu105526 жыл бұрын

    well explained. Thanks!

  • @jaimin92patel
    @jaimin92patel5 жыл бұрын

    Awsome. covered really good points.!

  • @ishmaelking3278
    @ishmaelking32785 жыл бұрын

    I’d love to see a system design video from a finance perspective.

  • @cirktap

    @cirktap

    3 жыл бұрын

    Well finance is very large complex topic

  • @zimmerhu
    @zimmerhu5 жыл бұрын

    Very good, Thanks!

  • @Snorkleboy
    @Snorkleboy6 жыл бұрын

    hash the license plates to spot numbers, have an overflow lot for hashing collisions.

  • @rajeevsai91
    @rajeevsai913 жыл бұрын

    Very nice stuff. Explained how to go about tackling the problem. Liked it. Thanks.

  • @spicytuna08
    @spicytuna085 жыл бұрын

    thx for the video. isn't there a need for unique lot ID per lot. this can be useful in locating a vehicle by using hashmap. when you park a car into a lot, store the location of the vehicle by map[license number] = parking lot ID. when to retrieve the vehicle, use the same hashmap to locate the lot. this is O(1). Also, usage of Redis would be handy. From your twitter video, understanding the characteristic of the parking lot. Usually, a car come and go within a couple of hours. There is no really need to store this info into a DB. When a car didn't leave this lot for more than 24 hours, this is the time to store into DB. I learnt a lot from you. Thanks a lot. Looking for your next video.

  • @niralkoradia7070
    @niralkoradia70705 жыл бұрын

    Kindly provide similar video on Airbnb, Netflix, Twitter, LinkedIn system design problems

  • @jameiealehandro
    @jameiealehandro2 жыл бұрын

    fantastic video! many thanks !

  • @Hdhfhfhc
    @Hdhfhfhc6 жыл бұрын

    Very nice detailed video. Thanks for the detailed explanation. But using stack only for tracking how many spots we are left with us is an overkill. Just use counters of any integer type. Increment it as you fill up and decrement it as spaces are free. If you are going to use the stack for a different purpose in future scalable design then that’s a different scenario. As of now stack DS doesn’t make much sense here. For coders out there, Guys coding in C++, can just use std::map instead of writing a hashmap DS, unlike java which has HashMap as a inbuilt container. One mote better powerful DS i can think of is using nested maps which can contain so many information at once. e.g std::map

  • @Spyron_
    @Spyron_6 жыл бұрын

    such explanation at least boost me and my confidence upto certain level.Thanks a lot sir.Actually helped me to think about what is software design and how to apply the OO concepts instead of only studying it.

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    Glad you like'd it! If you wanna do me a favor, share my videos on your social media =)

  • @viiids
    @viiids5 жыл бұрын

    Instead of using stacks, could have used a Priority Queue (keyed by distance from the entrance) so that when spots are returned back to the pool, they still appear in order of proximity from entrance.

  • @priyankarrajgupta4198

    @priyankarrajgupta4198

    3 жыл бұрын

    I was thinking same scenario, why let car parked at farthest slot from entrance when a slot is free near entrance. But this is will indeed increase TC. Its all about trade off and choices.

  • @yahuiz7877
    @yahuiz78776 жыл бұрын

    Great explanation!!!

  • @tanvijagtap8564
    @tanvijagtap85642 жыл бұрын

    This is really very helpful . Thank you so much for this video !! 😃

  • @green6564
    @green65646 жыл бұрын

    You got a new subscription

  • @RomanScherbatyuk
    @RomanScherbatyuk6 жыл бұрын

    I assume that it's a good idea to add parkinglot parameter into spot constructor because spot can't exist without parkinglot. Class hierarchy should represent some scope possibilities and limitations.

  • @kapil097
    @kapil0976 жыл бұрын

    Good one. Nice that you explained why to use stack and why Hashmap. This helps in decision making in similar situations . Please use bigger whiteboard so that entire problem can be seen at once. Waiting to see more such videos.

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +Kapil Sharma thanks for your feedback! What exactly would you like to see on the whiteboard? The problem statement, code or the architecture?

  • @kapil097

    @kapil097

    6 жыл бұрын

    The architecture. A bigger board will ensure you dont delete something which you have on the board already. That would also help in relating things if needed later in your talk.

  • @powder77777

    @powder77777

    6 жыл бұрын

    I think using a queue will work too.

  • @nitishshokeen4166

    @nitishshokeen4166

    5 жыл бұрын

    @@powder77777 Yes, using a queue instead of stack would work too. And the time and space complexities would remain the same for both stack and queue implementations.

  • @andrew5407
    @andrew54076 жыл бұрын

    great job Roman!

  • @GardeniaInc
    @GardeniaInc6 жыл бұрын

    I've feel relieved now..i thaught im weird used to think same idea..any issue in this world happen can lead to idea and benefit people then can make money with it.so summary is normal people think ordinary idea/act right? intelligent otherwise.Need to find circle who same think of view and attitude.

  • @KamalMettananda
    @KamalMettananda3 жыл бұрын

    Thanks a lot for making it look like a quite simple problem...

  • @RagingWhoremoans
    @RagingWhoremoans3 жыл бұрын

    For my interview I had to design a disaster plan for a political event, consisting of threat analysis, worst case scenarios, and evacuation routes. I wish they asked me this one instead.

  • @tobechukwunwatu848
    @tobechukwunwatu8485 жыл бұрын

    Great !! Thanks....i learnt alot

  • @SuccessinTech

    @SuccessinTech

    5 жыл бұрын

    Thank you!

  • @MrSRIVATSABR
    @MrSRIVATSABR5 жыл бұрын

    Hello Ramon, Thanks for the wonderful explanation. I was wondering if ParkingSpace could be a class and all the other sizes S, M, L, XL could be classes inheriting from ParkingSpace.

  • @tnvmadhav2442
    @tnvmadhav24426 жыл бұрын

    Thank you very much sir.I have learnt a big deal on the method of approach and points to be kept in mind

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +Tnv Madhav Happy I could help, don’t forget to subscribe and follow on Twitter @_SH4DY_ Have a good one!

  • @sharinganuser1539
    @sharinganuser15393 жыл бұрын

    This is my first system design question...and all i can think is pegion hole principle and some intelligent hashfunction....,didn't watched the video yet...let see how it goes. this was fun.....

  • @ankitm511
    @ankitm5115 жыл бұрын

    Wonderful explanation :) Super like (y)

  • @ppsanyal
    @ppsanyal6 жыл бұрын

    Please discuss a design question like "How do you design a music streaming service like Spotify?"

  • @punstress
    @punstress4 ай бұрын

    This is the second "design a parking lot" challenge I've seen, and this one is at least better than the first, which was for reserving specific spaces well in advance for a block of time (hours, not days) and I don't know why anyone would think to do that. No parking lot operates like that for a good reason: it would not work! Cars would stack up outside the lot waiting to enter for their block of time, because their space is not available until then. And what if they arrive and it's still occupied or the car next to him went over the line and they can't get in or out. So many problems. This POS system is somewhat better but, still, the idea of assigning a space is terrible. At least this one (theoretically) ensures that it's unoccupied, assuming the vehicle that just left actually did use the space they were assigned. Almost every lot charges upon leaving for obvious reasons. It's better to simply track how many spaces are available by how many have entered minus how many have paid, and let people find their own spots. This space-assigning system might be better for valet parking so they keep track of where the car is, which many times requires them moving other cars because they park them in tandem, or long-term parking by the week or month, or for really restricted number of spaces, such as a ferryboat or vehicle transport truck, train, or cargo ship.

  • @creative-freedom
    @creative-freedom6 жыл бұрын

    Nice video work clear explanation. Thanks!

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +Arun GK Thanks a lot! Would be awesome if you could share my videos with some friends or colleagues.

  • @merrichuffstutler5902
    @merrichuffstutler59023 жыл бұрын

    Ha! I gave this problem for over 50 interviews for Amazon.

  • @anilsinghkec
    @anilsinghkec3 жыл бұрын

    Instead of stack u can use a free list and used list (or used map). Getting parking and freeing parking will be O(1) and O(n)/O(1)

  • @paritosh850
    @paritosh8506 жыл бұрын

    This is really nice video. Very well explained. Well done man..

  • @zwunet
    @zwunet4 жыл бұрын

    Using HashMap in theory for this one sounds a good choice, in practice, it's much better to use a datastore such a table in a relational database (with indexing, keys, etc.). It also may resolve the concurrency issues here with help of transactions and extra attributes such as start/end times, cost, etc. for keeping the records. I don't think one will use the HashMap instead of a database table for this in a working system, particularly, the parking facility is a large one.

  • @himanshupoddar1395

    @himanshupoddar1395

    4 жыл бұрын

    I don't understand one thing suppose we use a database(say mysql) then why do we even need data structures, can't we just query from it and achieve our goals. Someone please specify!!!

  • @superwemanhella6240

    @superwemanhella6240

    Жыл бұрын

    @@himanshupoddar1395 Did you get an answer to this question? same thoughts!

  • @shakeelshahzad4045
    @shakeelshahzad40456 жыл бұрын

    Very best work sir. Can you please also make a video regarding Designing a shopping cart. And thank you very much for your valuable time and all the efforts you are making. Allah bless you.

  • @pranksmania275
    @pranksmania2752 жыл бұрын

    I think using to store vehicle or booked slot hashmap and stack it will be okay for single terminal. using DB would be good thing if you want to scale and have more than one terminals

  • @ryandruckman999
    @ryandruckman9995 жыл бұрын

    Also stack isn't O(1) operation, its O(s) where s is the ordinality of your different sizes. Maybe nitpick but it's not arbitrarily constant.

  • @marrowcrispy4449
    @marrowcrispy44496 жыл бұрын

    Thanks a lot, great explanation and details. I am wondering - why would you start design of class hierarchy with classes, instead of interfaces? I would say that here, having an interface ICar { String GetPlateNumber(); Enum GetSize(); } Is more than enough and for all the rest of the question we actually don't care, what kind of class hierarchy sits behind that interface. What do you thing about it?

  • @battushignamsraidorj4485
    @battushignamsraidorj44854 жыл бұрын

    Thank you,

  • @xuanyuhuang8461
    @xuanyuhuang84615 жыл бұрын

    better enhancement could be assign an x and y to each spot, the entrance of the park as (0, 0), all available spots pushed to a priority queue in which the spot closet to (0, 0) is at the top.

  • @infinteuniverse
    @infinteuniverse3 жыл бұрын

    We had a similar question when I took digital design class. We had to design a functioning parking lot controller using ONLY logic gates and flip flops. LOL

  • @awesomeit2020
    @awesomeit20203 жыл бұрын

    Awesome matey! Keep going man!

  • @SaurabhGoyal_jss
    @SaurabhGoyal_jss6 жыл бұрын

    If we optimize on the place-vehicle and remove-vehicle based on distance from entrance to the spot, we can use heap.

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +Saurabh Goyal Yeah, a min-heap on distance. Nice!

  • @romulo3385
    @romulo33856 жыл бұрын

    In the video there's a possible question about concurrency, like two cars checking for empty spots at same time. I think about synchronize only "checking spots" method, so I can only check for a free spot when there's no other Thread doing the same. Does anybody have any different thoughts about it or different cases for concurrency issues ?

  • @sandyethadka
    @sandyethadka5 жыл бұрын

    Something around a movie ticket booking service would be helpful

  • @wassimboussebha2561
    @wassimboussebha2561 Жыл бұрын

    question : in the findSpot() method , can i use a key-value hashmap , where you can map the available spots using the vehicle type , and i think that you can have one key and multiple values , but still O(n) since you need to traverse all the linked-list of the specific key

  • @abdulhakeemabdulrahman3105
    @abdulhakeemabdulrahman31056 жыл бұрын

    Very calm.

  • @Ritesh91188
    @Ritesh911886 жыл бұрын

    nice explanation!!!

  • @rodrigosouza9380
    @rodrigosouza93806 жыл бұрын

    Could you explain how to design a Task Scheduler system?

  • @ajaypadvi3350
    @ajaypadvi33506 жыл бұрын

    I got asked the similar question in an interview about train station design. There I messed up with concurrency part as multiple trains can arrive and depart from platforms simultaneously.. Could you please explain how would you go about handling concurrency in context of parking spots if there are multiple entrances and exits. That would give me a fair idea about train station problem. Thanks in advance. You have explained the problem to the depth and I am really looking forward to seeing other videos of yours.

  • @hiteshbitscs
    @hiteshbitscs6 жыл бұрын

    This is really nice way to approach a design a system problems. Can you also take example of systems like linkedin/twitter which are real time streaming solutions as well as systems like youtube/netflix/amazon prime like systems. 1. How do you approach a storage requirement? I think in big systems storage technology chosen is really important. 2. Do we need to give estimate of storage required if they give some number e.g. on your Twitter there are 100M users and your system should be able to scale upto 200M users for next 3 years. 3. How do we limit a design such a way that it's not too big but should be able to tell entire story in nutshell way. Thanks for your time and looking forward for more solutions and interactions.

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +Hitesh Patel Glad you liked it! Thank you for the feedback, I'm planning a video about streaming but to prepare it properly it will take some time. Regarding point 3: As long as you start from a high level at the beginning of the interview and mention the main features you can let the interviewer guide you and ask what part of the architecture you should dive into. So as long as you don't rush into one aspect of the design and keep *listening* and *asking* you don't have to worry much about the level of detail.

  • @hiteshbitscs

    @hiteshbitscs

    6 жыл бұрын

    Your recommendation on point 3 is really appreciated. Waiting for design systems like linkedin or twitter. I am not just here to get one way knowledge. I believe in sharing like you do. Some initial thought on twitter 1. Should allow to tweet 2. Should allow it's users to follow any one on twitter 3. Should able to get most recent feeds High level APIs 1. public void tweet(User user, Tweet tweet) User is a class which has name, geo, address, country etc. Tweet : char tweet[256], creation time, geo info, User id 2. public boolean follow(User follower, User wantToFollow) 3. public Feed[] getFeeds(); This looks very interesting problem. We can think this as a observer design pattern. If some celebrity tweets then follower should get into Feeder systems which sorts and gives N recent items and display it on UI. This can be push model to all interested people. Regarding steaming tech: As the user base is large here, the tweet can not be synced. Means twitter system can not guarantee ack immediately. As per CAP theorem it'll be eventual consistency as we want here Availability and parition tolerance. Kafka Queing can be used to queue user's tweet and then twitter systems can process it further. Storing in kafka means down the line we get scalability as number of consumers can be optimally equal to number of partitions in given kafka topic. NoSQL data base is a good fit to store users account info. As it scales way beyound relational db provides. All tweets can be stored in NoSQL db. Caching: We can keep celebrity id in cache as they are likely to tweet often and we need their tweet. Hence there are let say "S" celebrities and for in-memory distributed cache could be "Redis" as it scales well beyound one macine and this is in-memory. Let me know your feedback and forward how you approach this problem. Have a nice day.

  • @SuccessinTech

    @SuccessinTech

    6 жыл бұрын

    +Hitesh Patel Awesome, you covered a lot of ground with those topics. Your mentioning eventual consistency and you seem to know about the tradeoffs. You could dive deeper into the service architecture: How do you slice the architecture into pieces to enable horizontal scaling? You'll find more sys design videos on this channel soon, but also keep an eye out for others. I'm trying to share knowledge beyond interview, making us all better engineers.

  • @hiteshbitscs

    @hiteshbitscs

    6 жыл бұрын

    Thanks for reply. I first think product from users perspective. What should be done? What is USP of any given product. Try to optimize that usecase rather than small other usecases. e.g. In facebook status update is like realtime but to see my timeline can tolerate some delay. Hence i will not put timeline data into any cache. But feeds/status are near real time data that i can cache for some time. Then with CAP principle we can identify the victim by meeting systems end requirement in best possible way.

  • @smitti9
    @smitti96 жыл бұрын

    Wouldn't removeVehicle(vehicle: Vehicle) be a member class of ParkingLot? Since a spot could only hold one car?

  • @benleung6331
    @benleung63315 жыл бұрын

    It is interesting that no where in the demo talks about check-in time or check-out time of a vehicle. I would thought it is one of the most important feature of a parking lot

  • @dearruks3379
    @dearruks33793 жыл бұрын

    I feel placeVehicle and removeVehicle should be in the same class. Nonetheless, I enjoyed the breakdown!!