Remove more than two duplicates in-place

Problem Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result....

June 9, 2025

Inplace element removal an easy one

Problem Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things: Change the array nums such that the first k elements of nums contain the elements which are not equal to val....

June 7, 2025

The nicest way to merge two sorted arrays

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored....

June 6, 2025

gRPC - The Witchcraft of Remote Procedure Calls

WTF is gRPC? Why GRPC ? Some technologies are like witchcraft. You hear about them, you see them in action, but you don’t really understand how they work. gRPC is one of those technologies for me. It’s a remote procedure call (RPC) framework that allows you to define services and methods in a language-agnostic way, and then generate client and server code in multiple languages. So what it means is there is a ....

June 3, 2025

Replication - Leaders and Followers

Replication - Leaders and Followers Replication, or read replica is a process of copy pasting data from a primary database to another database. This is done to improve performance, availability, and reliability of the database. Replication can be done in two ways: synchronous and asynchronous. In synchronous replication, the primary database waits for the replica to acknowledge that it has received the data before it can proceed. This ensures that the data is always consistent between the primary and replica databases, but it can also slow down the performance of the primary database....

May 20, 2025

IP V4 Subnetting tricks and basics

IP V4 Subnetting tricks and basics Introduction As usual lets try to be little intellectual. By saying a qoute i got it from chatgpt. “Good subnetting is like good carpentry: measure twice, cut once.” What ever it means it doesnt matter. But the point is to understand the concept of subnetting and how it works. This is somehow one of the most mind f**k*ng topic which i encoutered during my job....

May 13, 2025

Utils

First tool: Subnet Calculator If you want to calculate the subnet, you can use the following tool. It will help you to calculate the subnet, broadcast address, and usable IP addresses. Loading message...

May 13, 2025

Enterprise Over Engineering

The Hidden Pitfalls of Overusing Design Patterns This is my story of using the Chain of Responsibility pattern after reading about it in a book while preparing for an interview. Yes — I actually used it in a real job. And well, it didn’t turn out the way I had imagined. Before we dive in, here’s a quote from one of my favorite authors, Khaled Hosseini (The Kite Runner): “There is only one sin, only one....

April 27, 2025

മധുരം മലയാളം. ഒരു മലയാളം പ്രോബ്ലം സോൾവിങ്

എനിക്ക് പലപ്പോഴും തോന്നിയിട്ടുണ്ട് നമ്മുടെ ഏതു ഭാഷയിലാണ് നമ്മളുടെ ബ്രെയിൻ പ്രവർത്തിക്കുന്നത് എന്ന്. ഇന്റർനെറ്റിൽ പരതുമ്പോൾ നമ്മുക്ക് മനസിലാകും ബ്രെയിൻ symbols ഉം മോഡലുകളും ആണ് ഉപയോഗിക്കുന്നത് എന്ന്. പക്ഷെ ഒരു പ്രോബ്ലം സോൾവ് ചെയ്യുമ്പോൾ നമ്മുടെ ബ്രെയിൻ കൂടുതൽ സമയവും ചിലവഴിക്കുന്നത് ഐഡിയകളെ പരിഭാഷ ചെയ്യാൻ ആയിരിക്കും. പ്രത്യേകിച്ച് മലയാളായി ആയ എനിക്ക് ഇതൊരു പ്രശ്നമായി തോന്നിയിട്ടുണ്. ചില പ്രോബ്ലെംസ് സോൾവ് ചെയ്യുമ്പോൾ എനിക്ക് കൂടുതൽ വഴങ്ങുന്ന ഭാഷ അത് മലയാളം ആണ്. ഉദാഹരണത്തിന് ഈ പ്രോബ്ലം നോക്കൂ. Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining....

April 6, 2025

Managing Concurrent Updates with Distributed Locks

Managing Concurrent Updates with Distributed Locks Managing Concurrent Updates with Distributed Locks In distributed systems, managing concurrent access to shared resources is crucial to ensure data consistency and prevent corruption. Let’s explore how to handle this using a Java example, starting with a basic implementation and improving it step-by-step. Basic Implementation Without Proper Lock Handling Here’s a simple version of a method that tries to acquire a distributed lock, perform an update, and release the lock:...

May 30, 2024