life is too short for a diary



Posts Tagged: java

Optimizing Builds with Gradle Build Cache

Gradle build cache is an essential tool for optimizing build times in software development. By storing build outputs either locally or remotely, it significantly reduces the time and resources required for rebuilding similar tasks. This cache mechanism is especially beneficial in continuous integration environments where builds occur frequently...

Continue reading → gradle java



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



Understanding Liskov Substitution Principle

The Liskov Substitution Principle, named after Barbara Liskov who introduced it in 1987, is one of the five SOLID principles of object-oriented design and programming. It states that..

Continue reading → oop java



Understanding final vs Static final in Java

Java provides various modifiers to control the behavior of classes, methods, and variables. Two such modifiers are final and static final. Let's delve deeper into their significance and differences...

Continue reading → java



Time Based Key-Value Store Solution

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp...

Continue reading → java leetcode



Mastering Reactive Pagination with Spring Boot and MongoDB

As we delve into the realms of sophisticated data management, we will be harnessing the strengths of Spring Boot, the agility of MongoDB, and the responsiveness of reactive programming to implement an efficient pagination system. Pagination is a critical feature, instrumental in enhancing user experience and application performance. By the end of this guide, you'll have a deep understanding of reactive pagination, equipping you with the skills to manage large data sets with ease and proficiency. Let's get started...

Continue reading → spring boot java mongodb



The number of Weak Characters in the Game

You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the ith character in the game....

Continue reading → java



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



Kata - Correct the Time String

In this [kata](https://www.codewars.com/kata/57873ab5e55533a2890000c7/), you are given a string that represents a time in the format "HH:MM:SS". The string may be in the wrong format, or it may be missing some characters. Your task is to correct the string so that it represents a valid time...

Continue reading → java javascript



TestContainers with Spring Boot

Testcontainers is a Java library that provides lightweight, disposable containers for running integration tests. It's a useful tool for testing applications that rely on external dependencies like databases or message queues...

Continue reading → java spring boot



Cribsheet for String in Java

Strings are immutable in java. It's best to convert string to StringBuilder/StringBuffer so that it's memory efficient for string manipulation...

Continue reading → java interview



Transforming a blocking method to a reactive one using Spring Reactor

Reactive programming is becoming increasingly popular in modern software development, and the use of reactive frameworks like Spring Reactor and RxJava is becoming more common. Reactive programming is an event-driven approach to programming that emphasizes asynchronous data streams, non-blocking I/O, and functional programming...

Continue reading → reactive programming java



Cribsheet for Set in Java

A set in Java is a collection that stores a unique set of elements. This means that there are no duplicates in a set. You can define set using HashSet, TreeSet, or LinkedHashSet...

Continue reading → java interview



Find if Path Exists in Graph leetcode solution

It's a easy problem on Graph in leetcode to find if a path exist in graph...

Continue reading → leetcode java



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



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



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 Graph Part 1

Graph are data structures made of vertices & edges. There are lots of interesting problems that can be solved using graphs. Part 1 covers the basic for creating a template for graph data structure...

Continue reading → graph java implementation



Recursively sort a array

I recently came across a simple telephonic interview problem. The problem was to sort an array recursively. But even numbers need to be placed before odd numbers. At first glance it was obvious that it was a simple case of implementation of merge sort...

Continue reading → algorithm java code



Three Sum Problem Leetcode Solution

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero...

Continue reading → leetcode two pointers java