Given a 32-bit signed integer, we want to generate the 32-bit signed integer obtained by reversing the digits of the original number. Incase, the result is beyond the range of a 32-bit signed integer, we return 0. To reverse a number we need to progressively extract the mod 10 and keep pushing into our new by first multiplying it by 10 and then adding the obtained digit from the original number. This is equivalent to extracting the digit, right shifting the given number, left shifting the new number and adding the digit. class Solution { public int reverse(int x) { long soln = 0; while(x != 0) { soln = 10 * soln + x % 10; x /= 10; } if ((soln > Integer.MAX_VALUE) || (soln < Integer.MIN_VALUE)) return 0; return (int)soln; } } The above code uses the constants from Integer class in java.lang package. However, this logic fails if we are given a 64-bit signed number, as we will not hav...
Photo by Kalen Emsley on Unsplash Setting the Stage Everyone of us across the world is suffering from the impact of Covid-19. From the health impact, to social loneliness, to unexpected layoffs, the immediate negative impact are just too many and on everyone of us. In this article, I am going to focus one aspect of the Covid-19, the lacklustre job situation all around. It may seem that this is going to never end, however this is not the first time economy has been impacted like this. I have myself witnessed such dismal situations atleast twice 2002 and 2008. The key to address this situation is to realize that right now if the market is low, it will rebound back in next 6–9 months, and what you have to do is to prepare for that upbeat mood when you can encash yourself. . . . Preparation — Putting Finances in Place In this article, I am going to detail about the computer engineers who are at the...