27 years of revolving around the sun

the below article is just my random thoughts..

Social Humour: Twitterati spots photo of a man leisurely smoking beedi,  turns it into a viral meme - The Times of India

The more i spend living my life, more it feels like a simulation. Its mostly like playing a boring game with no interesting stuff coming up. I am not even depressed or suicidal, i am content with myself. 


doug the lawyer I shouldnt be here (with text) fnaf - Imgflip


Sometimes i just feel like an NPC trying to do my part without questioning why I do what I do.

Share:

Leetcode milestone update, Reached 300



I managed to solve 300 in ~ 2 months, at this point i am quite comfortable with lot of topics. I am planning to focus my efforts on only solving hard rated challenges to improve my understanding. While i understand that it will be a frustrating experience, i would like to go through it :-)




Share:

Basic Calculator 2

 I always wondered about how to parse and execute complex numeric expressions, even though i did that my programming language agaram , i did that in a very different way ( using recursion ). So the problem statement here wants us to implement a program which parses the numeric expression. The expression consists of integers and operators ('+', '-', '*', '/') separated by some number of spaces and they guarantee that the expression would be valid. 

Share:

LC trick to parse number from a list of characters

 Lets say you have a string "leet23code" and you want to parse the characters as number 23, and you are not allowed to typecast after collecting the complete number "23" as string.

Its not really a trick but its just a nice way to build the number from string. 

The obvious way to do this is by multiplying the position of digit in number and adding it, for example 23 can be represented as

(2 * 10 ^ 1 ) + (3 * 10 ^ 0)

we would need to keep track of the power of 10 to build the number

something like


power = 0
my_number = 0
for c in s:
if c.isnumeric():
my_number += int(c) + 10 * power
power += 1


 This is  nice and easy to  understand, but there is even a better trick than this

def parse_number(self, s):
my_number = 0
for c in s:
if c.isnumeric():
my_number = my_number * 10 + int(c)
return my_number

 This reduces the need for keeping track of power, because we knew power is incremented every time.


Share:

Swim in rising water - Dijsktra optimization

 Problem statement:

You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).

The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim.

Return the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).

Share: