Skip to main content

Posts

Reversing Digits of a Number

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...
Recent posts

Rediscover, Rebound, Reimagine — Part 1

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...

Aarambh: The First Java Program

package Aarambh; class Aarambh { public static void main(String[] args) { System.out.println("!!! Hare Rama Hare Krishna !!!"); } }

Daily Reflections: May 24, 2020

Today I had a chance to go through two LinkedIn Learning courses -  The Six Morning Habits of High Performers ( Link ) Making Quick Decisions ( Link ) The first first audio course looked at six habits that high performers around the world practice and the second course elaborates on what it needs to make quick and good-quality decisions. A key observation from both the course was that they elaborated and formalized on advise that we get from our peers, mentors, and elders.

Salutations to Maa Saraswati

Its a tradition to invoke the name of Mother Saraswati before we embark on an intellectual pursuit.     Maa Saraswati Mantra  या कुन्देन्दुतुषारहारधवला या शुभ्रवस्त्रावृता  या वीणावरदण्डमण्डितकरा या श्वेतपद्मासना।  या ब्रह्माच्युत शंकरप्रभृतिभिर्देवैः सदा वन्दिता  सा मां पातु सरस्वती भगवती निःशेषजाड्यापहा ॥1॥  शुक्लां ब्रह्मविचार सार परमामाद्यां जगद्व्यापिनीं  वीणा-पुस्तक-धारिणीमभयदां जाड्यान्धकारापहाम्‌।  हस्ते स्फटिकमालिकां विदधतीं पद्मासने संस्थिताम्‌  वन्दे तां परमेश्वरीं भगवतीं बुद्धिप्रदां शारदाम्‌॥2॥  Meaning जो विद्या की देवी भगवती सरस्वती कुन्द के फूल, चंद्रमा, हिमराशि और मोती के हार की तरह धवल वर्ण की हैं और जो श्वेत वस्त्र धारण करती हैं, जिनके हाथ में वीणा-दण्ड शोभायमान है, जिन्होंने श्वेत कमलों पर आसन ग्रहण किया है तथा ब्रह्मा, विष्णु एवं शंकर आदि देवताओं द्वारा जो सदा पूजित हैं, वही संपूर्ण जड़ता और अज्ञान को दूर कर देने वाली माँ सरस्वती हमारी रक्षा करें॥1॥  शुक्लवर्ण वाली, संपूर्ण चराचर जगत्‌ में व्याप्त, आदि...