life is too short for a diary



Posts Tagged: python

Optimizing SQL Queries - Understanding and Refreshing Materialized Views

When to use a materialized view? And how does it perform against a normal view. Benchmarking using docker...

Continue reading → sql database python docker



Maximum Width of Binary Tree

The problem statement, as given on LeetCode, asks us to find the maximum width of a binary tree. The width of a level is defined as the number of nodes at that level. The maximum width of the binary tree is the maximum width among all levels...

Continue reading → python queue java



Binary Tree Right Side View Leetcode

We delve into a popular algorithmic problem from LeetCode: the "Binary Tree Right Side View". This problem is an excellent exercise for understanding tree-based data structures and breadth-first traversal techniques...

Continue reading → python queue java



Meetup at McColl School of Business at Queens University

I went to Charlotte Fintech Meetup. It was held in Room 326 of Sykes Hall, which is located in the McColl School of Business at Queens University. ...

Continue reading → charlotte finance python



House Robber Leetcode Solution

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night...

Continue reading → javascript java python rust



Publish to MSK Kafka using AWS Lambda Python

Apache Kafka is a distributed streaming platform designed to handle real-time data streams efficiently. It uses a publish-subscribe model, where producers publish messages to topics, and consumers subscribe to those topics to receive the messages. Amazon MSK simplifies the deployment and management of Kafka clusters on AWS, providing a fully managed and scalable solution. You can use AWS lambda in python to publish to MSK topic...

Continue reading → kafka aws python



Fix SonarQube Error of Public Writable Directories in AWS lambda python

In AWS Lambda functions, it's common to use temporary directories for tasks like generating temporary files, storing intermediate data, or processing data securely. However, improperly managing publicly writable directories can lead to security vulnerabilities. In this article, we'll explore how to address this issue and ensure safe usage of temporary directories in AWS Lambda functions using Python's tempfile module...

Continue reading → sonarqube python aws



Unit Test AWS Lambda Function in Python

AWS lambda function are event driven serverless code. To follow TDD, we should write unit test our lambda functions...

Continue reading → aws python



Pandas inner join on dataframes

Performing inner join on pandas dataframe is straightforward. However I wanted to override values from the right dataframe...

Continue reading → python pandas



Resolve the Error CROSSSLOT Keys in request don't hash to the same slot

AWS offers managed service Amazon MemoryDB which is redis compatible. The entire keyspace in Redis cluster is divided into hash slots and these slots are assigned to multiple nodes. In redis, getting a single value is straightforward...

Continue reading → python redis memorydb aws



Extract tweets from Twitter using Python

In this tutorial, we will extract tweets from Twitter using python...

Continue reading → python



Serialize and Deserialize Binary Tree Leetcode solution

Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure...

Continue reading → leetcode java python design



Apply Discount To Prices leetcode solution

A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign...

Continue reading → leetcode java python string



Sort Characters By Frequency solution leetcode

Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string...

Continue reading → leetcode java python heap



Create a Lambda Function to run SQL queries in Redshift Cluster

Amazon Redshift is fully managed warehouse service provided by AWS. The Amazon Redshift engine is a SQL-compliant, massively-parallel, query processing and database management system designed to support analytics workload...

Continue reading → python sql lambda function aws redshift



Getting Started with decorators in Python

In python, everything is an object. So functons are also objects which can be passed around. A decorator is a function that receives a function and returns a function...

Continue reading → python



Minimum Consecutive Cards to Pick up solution leetcode

An interesting problem on leetcode to find minimum number of ways to pick up consecutive cards. We will start with a brute force algorithm that would exceed in time limit. Later we will improve upon this algorithm using hashmap...

Continue reading → leetcode java python hashmap



Do you have triskaidekaphobia?

I grew up in India with a diet of basmati rice and superstition. I have seen pedestrians freezing at the sight of a black cat crossing their path for fear of bad luck. Lemon and chilis hang in front of vehicles to ward off bad spirits. I fondly remember numerous advertisements proclaiming protection from evil eyes. Recently I stumbled upon an ad that refreshed my memories...

Continue reading → superstition rationalism python



Creating Python AWS lambda layer with Docker

When you develop AWS lambda functions, you might feel the need to install additional `python` libraries. This can be achieved using Lambda layers that can be included in any lambda function...

Continue reading → docker aws python



Leetcode - All Divisions With the Highest Score of a Binary Array

You are given a **0-indexed** binary array `nums` of length `n`. `nums` can be divided at index `i` (where `0 <= i <= n`) into two arrays (possibly empty) numsleft and numsright..

Continue reading → leetcode hashmap array java python



Course Schedule Leetcode Solution

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai...

Continue reading → leetcode graph bfs java python



Remove-all-adjacent-duplicates-in-string-ii Solution

You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together...

Continue reading → leetcode stack python java scala javascript



Lowest Common Ancestor of a Binary Tree

Questions involving the binary tree data structure are very popular in tech interviews, and can be challenging and varied! A binary tree is a data structure consisting of a collection of nodes (starting at a root node), where each node consists of a value (data), together with a directed edges to at most two nodes (the "left child" and "right child"), with the additional conditions that no two edges point to the same node and no edge points to the root. I recently solved an interesting problem on binary tree...

Continue reading → leetcode java python javascript scala



Ternary String solution Codeforces - 1354B

Ternary string is an interesting problem that could be solved using two pointers techniques. It's a convenient way to keep track of multiple indices. This helps in making decisions based on two values...

Continue reading → codeforces two pointers java python



Coin Change solution leetcode

It's one of the most popular questions on leetcode that seems very easy at first. Coin change is a classic dynamic programming problem. I will proceed with an obvious (albeit wrong) solution and subsequently proceed to an efficient correct solution...

Continue reading → leetcode dp java python



Maximum Subarray

There's an interesting problem I recently solved on leetcode based on dynamic programming. My Github repository contains list of all problems that I have solved. I often start with a brute force approach without fretting about time complexity. Later I try to improve my algorithm for a better efficient solution...

Continue reading → leetcode dp java python



Getting Started with AWS CDK

Cloudformation service in AWS allows you to describe an entire set of resources required to make a pipeline. The cloudformation template can be described in JSON or YAML format. Updating the cloudformation template was not a pleasant experience. I wanted to discover alternative ways to generate cloudformation template programmatically...

Continue reading → aws cdk cloudformation typescript python



How to Make(Or Lose) Money in Stocks Part1

Recently I finished watching web-series Scam 1992. It's based on story of Harshad Mehta, a famous Indian stockbrocker who made fortunes in stocks. Despite his iconic success & failure, the series rekindled my interest in world of "stocks". I guess the famous dialogue "Risk Hai Toh Ishq Hai" has stuck with me...

Continue reading → stocks python finance money google selenium



EnvCommandError in Windows using Poetry

Poetry is a great dependency management tool in python. It's better than managing a flat file like `requirements.txt`. There are also other great tools like pipenv. However I found poetry much simpler in resolving dependencies...

Continue reading → windows python poetry bug



Connect to an Oracle Database using kerberos with python

Jobs failed! Screamed an automatic failure alert in email inbox. Existing python scripts were failing in the server which fetched data from Oracle database. I wondered if the credentials had changed...

Continue reading → kerberos projects python docker oracle database