Leetcode

237. Delete Node in a Linked List

The Singly-Linked List Conundrum Before delving into the intricacies of the Java solution, let’s understand the problem at hand. In a singly-linked list, each node contains a value and a reference to the next node in the sequence. The task is to delete a given node without access to the head of the linked list….

Java

How to initialise HashSet while declaring in Java

Before delving into initialization, let’s understand the allure of a HashSet. This data structure, based on the principles of a set in mathematics, provides rapid access to elements and ensures uniqueness—no duplicates allowed. Perfect for scenarios where order doesn’t matter, and you need swift membership checks. Techniques for Initializing HashSet During Declaration Method 1: Traditional…

Leetcode

1704. Determine if String Halves Are Alike

Problem: https://leetcode.com/problems/determine-if-string-halves-are-alike/description/ Breaking Down the Solution Converting String to Char Array: The input string s is converted into a character array a. This facilitates easy traversal and access to individual characters. Initialization and Set of Vowels: A HashSet vowels is created to store the vowels that need to be checked. The size of the array…

Leetcode

2385. Amount of Time for Binary Tree to Be Infected

Problem Statement: https://leetcode.com/problems/amount-of-time-for-binary-tree-to-be-infected/description/ Decoding the Algorithm: 1. Initialization and Connection Mapping: A HashMap (parentChildMap) is used to establish connections between child and parent nodes, essential for navigating the tree. The startNode is identified by traversing the tree until the desired node with the given value (start) is found. 2. Breadth-First Search (BFS): A LinkedList (queue)…

Leetcode

23. Merge k Sorted Lists

In the realm of algorithms and data structures, the task of merging k sorted linked lists is a familiar challenge. In this blog, we’ll embark on a journey through a naive approach and then pivot to a more optimal solution. Our starting point is a Java solution that might seem intuitive but lacks the efficiency…

Tech

A Guide to Linux Help Commands

Linux, with its powerful command-line interface, empowers users with a myriad of tools and utilities. Understanding how to navigate this vast ecosystem is crucial for efficient and effective system management. In this blog, we will explore key commands that provide invaluable help and documentation, namely whatis, man, –help, and apropos. 1. whatis – Unveiling the…

Leetcode

938. Range Sum of BST

Binary Search Trees (BSTs) are a fundamental data structure in computer science, known for their efficient search and retrieval operations. In this blog, we’ll delve into a Java solution for calculating the sum of values within a specified range in a BST. The provided code snippet showcases a recursive approach to achieve this task. Understanding…

Tech

What these $ and # symbol means in command line

The Linux terminal, with its command-line interface, is a powerful tool that offers users unparalleled control over their systems. As you navigate the terminal, you’ll encounter a variety of symbols in the prompt, each conveying important information about your current environment and permissions. In this blog, we’ll delve into the significance of these symbols and…

Tech

How to Write custom annotation in Micronaut

Introduction: Micronaut, with its lightweight and reactive architecture, has become a popular choice for building microservices. While the framework offers a plethora of built-in annotations, there may be scenarios where you want to tailor the behavior of your application with custom annotations. In this blog post, we’ll delve into the exciting realm of crafting custom…