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.
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)
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
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, "-"))
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.
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)
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:)
#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...............
why last part having this condition for i in range (n//2-1,-1,-1) please explain
i am also facing issues in understanding the lower part.
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.
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)
@@kuntalmukherjee695 see my solution given below your comment
@@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??
Sir can you please explain y did you write this (n//2-1,-1,-1)
Jabardast video.... 👌👌
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
Jabardast video sir ji
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, "-"))
Great 👍 keep learning 😊
Do share with your friends too 😊
Helpful session....
Happy to help
thanks for guidance
what an explantion pls make every video from haccerank python sir
Sure, will do😊
Keep learning keep supporting
nice explantion anna thank you very much
pls explain why not n//2 and not n/2
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.
Sir can you please explain this (n//2-1,-1,-1)
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)
OK thanku :)
plz explain why (n//2-1,-1,-1)
Bro hackerrank interview kit sahi hai kya interview practice ke liye?
Yes.. try to solve all the questions so that you can get flavour of each topic.
@@codingcart thanks brother
Why n//2?? This video it's so helpful and clear. Thank you!!
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:)
please explain why n//2, and not just n/2.
Check this one
ua-cam.com/video/GWXWnaaZeHE/v-deo.html
bhai kiyaa apny ye pehly attempt me hee kardiyaa yaa phir time lagaa isko solve karny me please tell me!!
Na na .. maine v galti kiya tha bahut😊
nice explantion anna
Thanks man!
Glad it helped😊. Please do share with your friends too😊
@@codingcart I don't have friends
Thank you very much
Glad it helped😊. Please do share with your friends too😊
#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...............
when you cant find a solution for this in c++ language ;(
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