System Design : Snake and Ladder | Low Level System Design | Machine Coding | OOPS Design

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 71

  • @hackstreet781
    @hackstreet781 2 ปีที่แล้ว +6

    I am starting with system design, yours is the first video I watched. Awesome tutorial.

  • @punitojha5560
    @punitojha5560 2 ปีที่แล้ว +21

    There are some modifications:
    1. We can use map to store ladder and snakes in the form of map[startPosition]=finalPosition.
    2. Instead of creating a queue and popping the front and pushing it to the back. Simply keep a fixed array and keep increment the index in a circular manner i.e index=(index+1)%noOfPlayers thus index will give the current player at any time

    • @username-tg7if
      @username-tg7if ปีที่แล้ว +1

      true no need to use deque

    • @shubhampatel7870
      @shubhampatel7870 5 หลายเดือนก่อน +5

      What happens if some player has won the game... you'll have to skip it's chance as well

    • @praveenbansal7973
      @praveenbansal7973 2 หลายเดือนก่อน

      what is the benefit of point 2?

  • @manishbolbanda9872
    @manishbolbanda9872 2 ปีที่แล้ว +1

    Simple approach a good start for beginners to lld(like me) to understand how machine coding would be. Thanks for the video and efforts.

  • @gajanankulkarni5535
    @gajanankulkarni5535 2 ปีที่แล้ว +13

    You can use map to store snakes and ladders insted of list. It will save for loop. Also builder pattern will be good to build gameboard.

    • @poojarajput827
      @poojarajput827 11 หลายเดือนก่อน

      Builder pattern how??

  • @shuvbhowmickbestin
    @shuvbhowmickbestin 6 หลายเดือนก่อน +3

    Could've refactored the if-else cascading at 15:03, the logic looks very reduandant at places. You could've done teh nextposition[0] == nextcell check once after checking for both the ladders and snaked. If (nextposition[0] > nextcell) {// ladder} else {// snake bit}

  • @mohitsinghal7870
    @mohitsinghal7870 3 ปีที่แล้ว +12

    code may be optimized, instead of creating the list of snake, ladder, and jumper, we can create a map for where the key is start point and value is endpoint, this way we can save time to search if target position is ladder/ snake or not int o(1) time,
    after searching on the internet, I think i am in right place for low-level designing

    • @TheTechGranth
      @TheTechGranth  3 ปีที่แล้ว +4

      You are right, it is just that the list will not be too big in a game like this, and readability wise it felt better hence my choice of list but time complexity wise you are right.
      Hope content are helpful. Do like and subscribe and share with others 🙂

    • @vinaysharma3871
      @vinaysharma3871 2 ปีที่แล้ว +1

      That O(1) optimisation you suggested is very good!

  • @pooranik5342
    @pooranik5342 2 หลายเดือนก่อน

    Extremely helpful.
    Thanks for the video bro.
    Please post more LLD videos

  • @m.sivaramtej4572
    @m.sivaramtej4572 21 วันที่ผ่านมา

    Timestamps
    00:04 - Introduction to low-level design of a customizable Snake and Ladder game.
    02:19 - Initialize game configuration for Snake and Ladder.
    04:32 - Designed a dice class and a generic jumper class for Snake and Ladder game.
    06:53 - Implemented game board features for Snake and Ladder.
    09:10 - Implemented game mechanics for starting and managing player turns.
    11:28 - Game logic manages player positions and winning conditions in Snake and Ladder.
    13:41 - Handling player movement for snakes and ladders in the game.
    15:58 - Game logic involves players, dice rolls, and handling snakes and ladders.
    18:12 - Overview of Snake and Ladder game board design.

  • @sakshisahu3983
    @sakshisahu3983 หลายเดือนก่อน

    Thanks for explaining in such an easy way

  • @helperclass
    @helperclass 2 ปีที่แล้ว +1

    Nice and simple explanation. Very helpful

  • @rishiraj2548
    @rishiraj2548 ปีที่แล้ว

    👍💯🙏 Welcome again

  • @puneettandon1815
    @puneettandon1815 2 ปีที่แล้ว +1

    Great content @TheTechGranth

    • @TheTechGranth
      @TheTechGranth  2 ปีที่แล้ว

      Glad it was helpful. Do like and subscribe and share with others 🙂

  • @sahilchawla9060
    @sahilchawla9060 2 ปีที่แล้ว +4

    Great Video. Thanks for that. I have a question.
    In your design, the game board is tightly coupled with the classes like dice, jumper, player, etc. We could have made them loosely coupled through interfaces. But writing interfaces for all the classes here would take a lot of time and we may run out of time for writing this code. What is the expectation in the interview?

  • @rajaganesh7477
    @rajaganesh7477 10 วันที่ผ่านมา

    It would be good if you share the LLD diagram for this.

  • @dilipvenkatesh
    @dilipvenkatesh หลายเดือนก่อน

    @TheTechGranth Ensure that no ladder endpoint coincides with a snake start point, and no snake endpoint coincides with a ladder start point. I think we need to add this conditions.

  • @trendingtalks3963
    @trendingtalks3963 ปีที่แล้ว +1

    Jump part is little complicated for beginners. Please try making it simpler.

  • @hackstreet781
    @hackstreet781 2 ปีที่แล้ว +2

    I have one query, when someone ask me to do a low level design, what is the output he is expecting? Code or some diagram

  • @akshaynanavare2606
    @akshaynanavare2606 2 ปีที่แล้ว

    Great video brother ❤️❤️

  • @nitinkhulbe6234
    @nitinkhulbe6234 3 ปีที่แล้ว +6

    I think the loop in which you are trying to find snake bottom position or ladder jump position could have been done using a hashmap

    • @TheTechGranth
      @TheTechGranth  3 ปีที่แล้ว +3

      Yes you are right, thanks for suggestion

  • @adilmahmood9098
    @adilmahmood9098 2 ปีที่แล้ว

    ideally getting the current position from the positions map should mapped via the player id instead of the player name

  • @thealgomasters
    @thealgomasters 10 หลายเดือนก่อน

    Awesome video!

  • @karankanojiya7672
    @karankanojiya7672 3 ปีที่แล้ว +1

    Respect++
    Excellent !

    • @TheTechGranth
      @TheTechGranth  3 ปีที่แล้ว

      Glad it was helpful. Do like and subscribe and share with others 🙂

  • @soumikdey1456
    @soumikdey1456 2 ปีที่แล้ว +1

    Hi, you have any lld of virtual machine creation system design?

    • @TheTechGranth
      @TheTechGranth  2 ปีที่แล้ว

      Can you elaborate the problem pls

  • @Anesu98
    @Anesu98 20 วันที่ผ่านมา

    i think you should start from use case diagram, class diagram then come to the actuall code

  • @abhireddy8164
    @abhireddy8164 3 ปีที่แล้ว +2

    Sir what if we can make Obstacle as interface and let snakes and ladders implement from it .In future if you want to add any other obstacles we can do that by extending the code i.e open for extension and closed for modification....and one thing sir if we want to invert to rules i.e snakes become ladders and viceversa...i.e when ever you hit the tail of snake you can upwards up to the head...and viceversa for ladders...How do that sir with minimal modifications.? where user select the rules based up on his interest..

    • @TheTechGranth
      @TheTechGranth  3 ปีที่แล้ว +1

      1) You can do that as well but then in that case the game will not be snake and ladder :) I felt it will just be a overhead in this scenario, considering you just have to move up or down based on if it is a snake or a ladder but your point will make more sense in case we had some complex algorithm which differentiates snake from a ladder and in future we have possibility to add more obstacle.
      2) this is what jumper will do, when you load the board, you have get input for user details and positioning of snake and ladder, just name the jumper as snake and give it the functionality of ladder, no modification required in current code to answer your 2nd point.
      But then again, even though it is technically feasible, you wont do that in general.

    • @abhireddy8164
      @abhireddy8164 3 ปีที่แล้ว +1

      Thank you sir ..

  • @AkshaySharma-bg3oj
    @AkshaySharma-bg3oj ปีที่แล้ว

    great one man.

  • @shubhampokhriyal8491
    @shubhampokhriyal8491 2 ปีที่แล้ว +4

    Is low level. Design and machine coding round same?

    • @TheTechGranth
      @TheTechGranth  2 ปีที่แล้ว

      No, low level design can be extended to be a machine coding. In low level design you are supposed to design the api and class and relation between classes using design principles and patterns, futher you can be asked to implement few methods which falls under machine coding

    • @shubhampokhriyal8491
      @shubhampokhriyal8491 2 ปีที่แล้ว +1

      @@TheTechGranth so low level. Design is subset of machine coding?

    • @TheTechGranth
      @TheTechGranth  2 ปีที่แล้ว

      @@shubhampokhriyal8491 not exactly, in machine coding, you can be given the class and methods, and you need to code the algorithm

    • @shubhampokhriyal8491
      @shubhampokhriyal8491 2 ปีที่แล้ว +1

      @@TheTechGranth and in low level. Design no. Code?

    • @TheTechGranth
      @TheTechGranth  2 ปีที่แล้ว

      @@shubhampokhriyal8491 ideally yes but you may be asked to code some methods as well, depends on your years of experience and your interviewer

  • @kumarabhishek7877
    @kumarabhishek7877 2 ปีที่แล้ว

    Bahut badhiya

  • @vikramshah1286
    @vikramshah1286 3 ปีที่แล้ว +4

    I think variable b can be renamed as climbed and will make more sense By the ways thanks for explaining

    • @TheTechGranth
      @TheTechGranth  3 ปีที่แล้ว +1

      Yes you are right, variable naming is really important while coding in real project and interviews both.
      Hope it was helpful. Do like and subscribe and share with your friends 🙂

    • @technotutors1970
      @technotutors1970 2 ปีที่แล้ว

      we can also use else if statements to eliminate the use of variable b I guess

  • @username-tg7if
    @username-tg7if ปีที่แล้ว

    improvement : no of snakes and no of ladders should nt be hard coded . We need to make it randomly for every new game

  • @ajaywadhwa3398
    @ajaywadhwa3398 3 ปีที่แล้ว

    Good Job Dude.

    • @TheTechGranth
      @TheTechGranth  3 ปีที่แล้ว

      Thanks. Do check out other videos. Please like and subscribe, and share with your friends :)

  • @mr.pathaka5132
    @mr.pathaka5132 2 ปีที่แล้ว

    I think rollDice will return 2 to 11 if we pass numberOfDice 2?

    • @deepanshupal400
      @deepanshupal400 ปีที่แล้ว

      yes 12 will never achieved with two dice,seems wrong to me

    • @megansteven7688
      @megansteven7688 8 หลายเดือนก่อน

      i think there is some mistake in generating diceRoll
      (((int)( Math.random() * 6*2 - 2)) + 1);
      if numberOfDice = 2, then 12-2 = 10 + 1 = 11 we never achieve 12.
      Edit: Instead we can use this (((int)( Math.random() * 6*numberOfDice)) + 1), correct me if i am wrong.

  • @Aman_Gupta54
    @Aman_Gupta54 2 ปีที่แล้ว

    should i really study system design, I am a fresher and getting out of college

  • @architsri94
    @architsri94 4 ปีที่แล้ว +16

    I think you're giving equal probability to all numbers for more than 1 die, but actually, probability of 5 (4+1, 2+3, 3+2, 1+4) is different than say 2 (1+1)
    Just a thought 😅

    • @TheTechGranth
      @TheTechGranth  4 ปีที่แล้ว +2

      Thank you, that is a very valid point and a very good observation.

    • @TheTechGranth
      @TheTechGranth  4 ปีที่แล้ว +2

      twitter.com/GranthTech/status/1346469536799682561

    • @architsri94
      @architsri94 4 ปีที่แล้ว +3

      @@TheTechGranth Growing together :-)

    • @TheTechGranth
      @TheTechGranth  4 ปีที่แล้ว

      @@architsri94 Do check out the other videos and provide your valuable feedback. Do not forget to share it with your friends, like and subscribe.

    • @umangmalhotra1222
      @umangmalhotra1222 3 ปีที่แล้ว

      Very Good Observation, Infact he should not include number of dice variable in Dice class, because that is not a property of Dice class. It should be a property of Dice Provicer.

  • @AditiAgarwal-rw3lq
    @AditiAgarwal-rw3lq ปีที่แล้ว

    do we have to do this necessarily in java?

  • @megansteven7688
    @megansteven7688 8 หลายเดือนก่อน +2

    i think there is some mistake in generating diceRoll
    (((int)( Math.random() * 6*2 - 2)) + 1);
    if numberOfDice = 2, then 12-2 = 10 + 1 = 11 we never achieve 12.
    Edit: Instead we can use this (((int)( Math.random() * 6*numberOfDice)) + 1), correct me if i am wrong.

    • @ayushigupta685
      @ayushigupta685 7 หลายเดือนก่อน +1

      but it will reach 13 then?

    • @megansteven7688
      @megansteven7688 7 หลายเดือนก่อน

      @@ayushigupta685 i tried but didn't got 13, can you try once.

    • @palakgupta728
      @palakgupta728 7 หลายเดือนก่อน

      Math.random has a syntax of
      int rand = (int)(Math.random() * range) + min;
      So i guess it should be
      (int)(Math.random() * 6*numberOfDice) + 2;
      Because we can never get 1
      Correct me if I am wrong