This would take me some time to figure out. Then you realise you need to do about 150-200 problems to be comfortable at some level in level...phew....good luck everyone
I think the key learning here for me was that only ever 1 character to the left of a larger value can be a "Subtract" value. E.g. you can never get IIV or XXL I was in a loop trying to figure out how to see if I need to check next 1 or 2 characters, when it can only ever be the next one. Great video, helped a lot!
Cool! this is very explanatory and you made look easy thanks!. Only one feedback It will be good to use a better variable names instead of d, n, i. This just to help new people.
This code is bit more complicated than it needs to be. If you have a subtraction as in the number "XL", when you get to 'X', check that it's less than L, and subtract 10. Continue your algorithm with the next character 'L' and add 50 for that one. In my code, I initialize SUMM with the value of the last character since we know it will never be subtracted. Then you can iterate through s[:-1], or better yet use zip(s, s[1:]) to check each character against its neighbor and you don't have to worry about keeping track of an index at all.
i think using stacks is more intuitive, because when we manually calculate by hand we build up stacks until we hit a element whose value is less than the stack[-1]
Same logic, but different implementation: " def romanToInt(self, s: str) -> int: symbol_table = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} converted = 0 n = len(s) for index in range(0, n): if index
the biggest thing is being able to segment parts of the question into smaller specific patterns of logic that are more easily programmable. so for example, you know you have specific cases for the numbers 4 and 9, 40 and 90, and 400 and 900 based off specific rules dictated by the question. so you know to have if conditions checking for those numbers, etc. it takes time and practice. Dont just answer a question, but learn to deconstruct a question till you can understand the necessary aspects of it, and then construct a solution based off of it.
Master Data Structures & Algorithms For FREE at AlgoMap.io!
This would take me some time to figure out. Then you realise you need to do about 150-200 problems to be comfortable at some level in level...phew....good luck everyone
WOW, you made it look very easy , I love your teaching method!
I think the key learning here for me was that only ever 1 character to the left of a larger value can be a "Subtract" value. E.g. you can never get IIV or XXL
I was in a loop trying to figure out how to see if I need to check next 1 or 2 characters, when it can only ever be the next one. Great video, helped a lot!
Cool! this is very explanatory and you made look easy thanks!. Only one feedback It will be good to use a better variable names instead of d, n, i. This just to help new people.
This code is bit more complicated than it needs to be. If you have a subtraction as in the number "XL", when you get to 'X', check that it's less than L, and subtract 10. Continue your algorithm with the next character 'L' and add 50 for that one.
In my code, I initialize SUMM with the value of the last character since we know it will never be subtracted. Then you can iterate through s[:-1], or better yet use zip(s, s[1:]) to check each character against its neighbor and you don't have to worry about keeping track of an index at all.
Great Video! but if a map is needed, why is this problem on 'array & Strings' Section?
That is pretty much leetcode It is always a combination of concepts
i think using stacks is more intuitive, because when we manually calculate by hand we build up stacks until we hit a element whose value is less than the stack[-1]
No way this is an easy question lol 😂
Same logic, but different implementation:
"
def romanToInt(self, s: str) -> int:
symbol_table = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
converted = 0
n = len(s)
for index in range(0, n):
if index
Is this really an easy question? It takes time for beginners like me to notice that
the biggest thing is being able to segment parts of the question into smaller specific patterns of logic that are more easily programmable. so for example, you know you have specific cases for the numbers 4 and 9, 40 and 90, and 400 and 900 based off specific rules dictated by the question. so you know to have if conditions checking for those numbers, etc. it takes time and practice. Dont just answer a question, but learn to deconstruct a question till you can understand the necessary aspects of it, and then construct a solution based off of it.
Technically, no, it is not a beginner, but it is not medium either.
I think the interviewer who dislike me give me this type of question.
bro this is tough question
I honestly appreciate the feedback, it helps me plan the pathway