Designer Door Mat [HackerRank] | Python | String

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 44

  • @nagaiahamarnath2803
    @nagaiahamarnath2803 4 роки тому +7

    why last part having this condition for i in range (n//2-1,-1,-1) please explain

    • @kuntalmukherjee695
      @kuntalmukherjee695 3 роки тому

      i am also facing issues in understanding the lower part.

    • @codingcart
      @codingcart  3 роки тому

      For making simple i have divided the problem in 3 part
      eg: for value 9 i have divided 9//2 to get 2 half (4,4 for upper and lower) .
      9=(4 1 4)
      4 -->for upper part
      1--> for middle, I have kept the constant string 'WELCOME'
      4--> for lower part , and for the lower half part we have to print our required design in decreasing order, so we are iterating the for loop in decreasing order.
      Hope this helps:)
      If you are still facing problem, try to execute by printing the i value and print statement of the above code.

    • @aish1654
      @aish1654 3 роки тому +5

      See,
      In this example n = 9
      # (n//2)
      So n//2 means 9//2 which gives us 4.
      # suppose we take ((n//2) , -1)
      this is the range. It will give (4,-1) But in the range function in python, the last value won't be considered. SO PYTHON WILL CONSIDER IT AS (4,0) only. That's why we're giving range till -1.
      # ((n//2), -1, -1)
      so we have our actual range as (4,0) both inclusive. Now the third -1 states that we want to DECREMENT BY 1 in each iteration.
      Hence, at 8:00 the iteration is going from 4,3,2,1,0 so we get 5 rows.
      BUT WE WANTED ONLY 4.
      So, we decreased the higher range also by 1.
      Hence, ((n//2)-1), -1, -1)

    • @Abhijit_SU
      @Abhijit_SU 3 роки тому +1

      @@kuntalmukherjee695 see my solution given below your comment

    • @BharatBuild
      @BharatBuild 9 місяців тому

      ​@@aish1654 if that's the issue then ..why don't we use (n//2,0,-1)...this will also give 4 rows but its failing the test cases??

  • @biancakanchi3054
    @biancakanchi3054 3 роки тому +2

    Sir can you please explain y did you write this (n//2-1,-1,-1)

  • @amanrajan2732
    @amanrajan2732 4 роки тому +3

    Jabardast video.... 👌👌

    • @codingcart
      @codingcart  4 роки тому

      Hey, have you checkout one of the most frequently asked question in Interview from LinkedList.
      If you like don't forget to like, comment, subscribe and share with others.
      If you have any thought , please feel free to comment.
      ua-cam.com/video/WcOdcUHOA1M/v-deo.html

  • @AmanKumar-rr1qx
    @AmanKumar-rr1qx 4 роки тому +2

    Jabardast video sir ji

  • @WildStarvingWolf
    @WildStarvingWolf Рік тому +1

    Hi. I saw your Rangoli video and it was very helpful so I could understand how this works.. it allowed me to solve the door mat problem by myself, but my solution was not as efficient as yours (probably my lack of experience since I'm still learning), but I think this might be a bit easier to understand for those that like me are not so much experienced:
    nm = input().split(" ")
    # number of rows as "n"
    n = int(nm[0])
    # width as "m"
    m = int(nm[1])
    # diamond pattern element
    p = ".|."
    # center row with text
    word = "WELCOME"
    center_row = word.center(m, "-")
    # (n - 1) / 2 (formula for determining half the size of rows minus the center row
    half = (n - 1) / 2
    pattern = p
    for i in range(half):
    print(pattern.center(m, "-"))
    pattern += p * 2
    print(center_row)
    for i in range(half):
    pattern = pattern.replace(p, "", 2)
    print(pattern.center(m, "-"))

    • @codingcart
      @codingcart  Рік тому

      Great 👍 keep learning 😊
      Do share with your friends too 😊

  • @AbhishekKumar-ob7vh
    @AbhishekKumar-ob7vh 4 роки тому +5

    Helpful session....

  • @tanmaybhalerao8872
    @tanmaybhalerao8872 4 роки тому +5

    thanks for guidance

  • @shrikantjha4686
    @shrikantjha4686 3 роки тому +2

    what an explantion pls make every video from haccerank python sir

    • @codingcart
      @codingcart  3 роки тому

      Sure, will do😊
      Keep learning keep supporting

  • @Pardhu-g5g
    @Pardhu-g5g 2 місяці тому

    nice explantion anna thank you very much

  • @TJ-wo1xt
    @TJ-wo1xt 3 роки тому

    pls explain why not n//2 and not n/2

  • @codingcart
    @codingcart  4 роки тому

    Hey Programmer, if you enjoyed this video checkout my latest video ua-cam.com/video/lBVAznAZ39A/v-deo.html of Alphabet Rangoli problem from HackerRank and don't forget to like, comment, subscribe and share with others.

  • @akankshayadav3608
    @akankshayadav3608 3 роки тому +2

    Sir can you please explain this (n//2-1,-1,-1)

    • @aish1654
      @aish1654 3 роки тому +4

      Let me try to explain. :)
      In this example n = 9
      # (n//2)
      So n//2 means 9//2 which gives us 4.
      # suppose we take ((n//2) , -1)
      this is the range. It will give (4,-1) But in the range function in python, the last value won't be considered. SO PYTHON WILL CONSIDER IT AS (4,0) only. That's why we're giving range till -1.
      # ((n//2), -1, -1)
      so we have our actual range as (4,0) both inclusive. Now the third -1 states that we want to DECREMENT BY 1 in each iteration.
      Hence, at 8:00 the iteration is going from 4,3,2,1,0 so we get 5 rows.
      BUT WE WANTED ONLY 4. And also the design is out-of-place there.
      So, we decreased the higher range also by 1.
      Hence, ((n//2)-1), -1, -1)

    • @akankshayadav3608
      @akankshayadav3608 3 роки тому +1

      OK thanku :)

  • @lahari817
    @lahari817 Рік тому

    plz explain why (n//2-1,-1,-1)

  • @rajneesh9860
    @rajneesh9860 2 роки тому

    Bro hackerrank interview kit sahi hai kya interview practice ke liye?

    • @codingcart
      @codingcart  2 роки тому +1

      Yes.. try to solve all the questions so that you can get flavour of each topic.

    • @rajneesh9860
      @rajneesh9860 2 роки тому

      @@codingcart thanks brother

  • @ruddysimon727
    @ruddysimon727 4 роки тому +1

    Why n//2?? This video it's so helpful and clear. Thank you!!

    • @codingcart
      @codingcart  4 роки тому +1

      Glad it was helpful!
      For making simple i have divided the problem in 3 part
      eg: for value 9 i have divided 9//2 to get 2 half (4,4 for upper and lower) .
      9=(4 1 4)
      4 for upper part
      1 for middle, I have kept the constant sting 'WELCOME'
      4 for lower part
      Hope this helps:)

  • @TJ-wo1xt
    @TJ-wo1xt 3 роки тому

    please explain why n//2, and not just n/2.

    • @codingcart
      @codingcart  3 роки тому

      Check this one
      ua-cam.com/video/GWXWnaaZeHE/v-deo.html

  • @salmanmallah1425
    @salmanmallah1425 2 роки тому

    bhai kiyaa apny ye pehly attempt me hee kardiyaa yaa phir time lagaa isko solve karny me please tell me!!

    • @codingcart
      @codingcart  2 роки тому

      Na na .. maine v galti kiya tha bahut😊

  • @Pardhu-g5g
    @Pardhu-g5g 2 місяці тому

    nice explantion anna

  • @Z_nix
    @Z_nix Рік тому +1

    Thanks man!

    • @codingcart
      @codingcart  Рік тому

      Glad it helped😊. Please do share with your friends too😊

    • @Z_nix
      @Z_nix Рік тому

      @@codingcart I don't have friends

  • @razarajpoot9811
    @razarajpoot9811 Рік тому +1

    Thank you very much

    • @codingcart
      @codingcart  Рік тому

      Glad it helped😊. Please do share with your friends too😊

  • @_mandeep_kumar.
    @_mandeep_kumar. 4 роки тому +4

    #Replace all ______ with rjust, ljust or center. Hackerrank problem
    height = int(input()) #This must be an odd number
    weidth = int(input())
    c = '.|.'
    string = "WELCOME"
    #Top Cone
    we = weidth//2
    for i in range(height//2):
    print((c*i).rjust(we-1,"-")+c+(c*i).ljust(we-1,"-"))
    #middle Core
    print(string.center(weidth,"-"))

    #Bottom Cone
    for i in reversed(range(height//2)):
    print((c*i).rjust(we-1,"-")+c+(c*i).ljust(we-1,"-"))
    is this ok for this problem...............

  • @spencercarden7748
    @spencercarden7748 2 роки тому +1

    when you cant find a solution for this in c++ language ;(

  • @JagratiMaran
    @JagratiMaran 3 роки тому +5

    things you should know:
    for i in range(1,11):
    print(i)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    for i in range(1,11):
    print(i, end="")

    12345678910
    for i in range(1,11):
    print(i, end=" ")
    1 2 3 4 5 6 7 8 9