wat if v2 - v1 is 0? when i put custom input as 70 2 43 2 the answer came YES even tho logically thinking they should never meet but surprisingly when the input is 43 2 70 2 the answer is right which is NO it would be great if u could explain y is that
Excellent remark, Iman, and that is a mistake I have just fixed (see the video's updated description). The explanation for YES with the input "70 2 43 2" initially is that when x1 - x2 gets evaluated, it returns 27, and 27 divided by zero (because v2 - v1 equals zero in this case) evaluates to an infinity value (or INF). So, when we check if the infinity value is equal to the floor of itself (TRUE) and if the infinity value is greater than or equal to 0 (also TRUE), our condition evaluates to TRUE and so we return the string "YES". But when you change the custom input to "43 2 70 2", then this time, x1 - x2 gives us -27. That's a negative value, and when you divided -27 by zero, you get a negative infinity value. So here, when we check if that negative infinity value is equal to the floor of itself (TRUE) and if that negative infinity value is greater than or equal to zero (FALSE), then our condition evaluates to FALSE, and so we execute the last return statement instead, which returns "NO". But this was a flaw in my logic, which I had overlooked, so I have now updated my code and posted it as a public file on GitHub (also in the description of this video now). Here is the link: gist.github.com/IsaacAsante/d2a6eb21c1a4c6757930fd6c8ce5143e You will notice that the condition in the function now uses the isinf() function in C++ to verify if the "res" value is an infinity value or not. If it is, our condition will automatically evaluate to FALSE, and so the answer will be "NO". Hope it's clear to you now, and thanks a lot for pointing out that mistake which was not covered by the test cases on HackerRank.
@@nextrie I think there is still a problem with the updated code. I am not that capable in writing code in c++ but for example, if you check the case 0 2 0 2 then the kangaroos will meet after the first jump. Still abs(v2 - v1) = 0 but you have to return "YES". Am I right??? I used one more if statement to account for this.
Have you thought about creating a discord group for Competitive Programming, Coding Challenges or IT stuff in general? I think you should. I often follow your videos, it would be great to be in a group with people interested in Coding Challenges in which we can support each others, think about it !
Hey, thanks for the suggestion! I might create a Discord group in the future indeed, so look out. Thanks a lot for following my content. It means a lot.
I'm sure there is, just don't give up I know your channel isn't that big (yet) but you're indeed helping people to understand and learn useful stuff and I personally thank you for that. I hope that discord channel to come to us as soon as possible !
I'll keep pushing and making sure I help as much as I can. I've got more videos coming soon about trees, graphs and every other HackerRank topic. And yes, I'll announce once I start growing my community with Discord and other platforms. Thanks! :)
Hey mate can u suggest another approach of this problem using while loop, eg: while(x1>x2 || v1>v2) like i tried this one but thrown me a "Run Time Error"
Hi Anas, you don't have to use an iteration-based approach (e.g. a loop) to solve this challenge. Otherwise, this will negatively affect the time complexity of your solution and may unnecessarily extend the execution time of your program. Feel free to play around with the solution from my GitHub: github.com/IsaacAsante/HackerRank/blob/main/Problem%20Solving/Algorithms/Implementation/Number%20Line%20Jumps/number%20line%20jumps.cpp
Hey Ankit, this is because I am performing a division. Whenever you need to store the result of a division operation in a program, it's always good practice to declare the variable (used for the result of the division) as a double. For example, 10 / 3 or 24 / 7... these divisions give us floating point numbers which are best stored in variables declared as float or double (depending on the maximum value you expect).
@@AnkitPandey-es7wk I understand your question now. What I'm doing here is called "casting". I'm forcefully casting the result of the division into a double, and storing it in my double-type variable called res. The reason for that is because I'm passing my res variable to the floor() function on the next line, as part of my algorithm. But the floor() function in C++ expects its argument to be of type double, and not int. Now, imagine that the value of the division in the previous line was an integer, e.g. 21 / 3 = 7. In this case, I want the integer value 7 to be converted into the floating point value 7.0, so that I can store it in my res variable of type double. This way, I can pass my res variable (now with the double-type value 7.0) to the floor() function afterward without causing any error. Does that answer your question?