Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

1,958 articles

How to search in a row wise increased matrix using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 248 Views

Searching in a row-wise sorted matrix is a common algorithmic problem where each row and column is sorted in ascending order. The naive approach of scanning all elements takes O(M×N) time complexity, but we can optimize this using a smart traversal strategy. The key insight is to start from either the top-right corner or bottom-left corner of the matrix. From the top-right position, if the target is smaller than the current element, move left; if larger, move down. This approach eliminates either a row or column in each step. Algorithm The search algorithm works as follows − ...

Read More

How to find all unique triplets that adds up to sum Zero using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 445 Views

The three-sum problem involves finding all unique triplets in an array that sum to zero. This is a classic algorithmic challenge that can be solved efficiently using a two-pointer technique after sorting the array. Problem Statement Given an array of integers, find all unique triplets where nums[i] + nums[j] + nums[k] = 0. The solution must avoid duplicate triplets. Approach 1: Brute Force The simplest approach uses three nested loops to check every possible combination of three elements − Time Complexity − O(n³) Space Complexity − O(1) Approach 2: Optimized Two-Pointer Technique ...

Read More

How to find the shortest distance to a character in a given string using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 429 Views

Finding the shortest distance to a character in a string requires calculating the minimum distance from each position to the nearest occurrence of the target character. This can be efficiently solved using a two-pass approach that scans the string from left to right and then from right to left. The algorithm maintains two arrays to track distances from both directions, then combines them to find the minimum distance at each position. Syntax Following is the method signature for finding shortest distances − public int[] ShortestDistanceToCharacter(string s, char c) Parameters s − ...

Read More

How to find the unique triplet that is close to the given target using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 279 Views

The Three Sum Closest problem asks us to find a triplet of numbers in an array whose sum is closest to a given target value. This problem uses the Two Pointers pattern and is similar to the Triplet Sum to Zero problem. We iterate through the array, taking one number at a time as the first element of our triplet. For each fixed element, we use two pointers to find the best pair that makes the triplet sum closest to the target. At every step, we save the difference between the triplet sum and the target, comparing it with ...

Read More

How to find all the unique quadruplets that is close to zero using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 294 Views

Finding all unique quadruplets that sum to zero in C# is a classic algorithmic problem known as the 4Sum problem. The goal is to find all combinations of four distinct elements from an array whose sum equals zero, avoiding duplicate quadruplets. Problem Approaches There are multiple approaches to solve this problem, each with different time and space complexities − Approach Time Complexity Space Complexity Description Brute Force O(n4) O(1) Four nested loops checking all combinations HashSet Optimization O(n3) O(n) Use HashSet to find fourth element Two ...

Read More

How to find the quadruplet that is close to target using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 198 Views

The quadruplet closest to target problem involves finding four numbers in an array whose sum is closest to a given target value. This is solved using the Two Pointers pattern, similar to the quadruplet sum to zero approach. The algorithm works by sorting the array first, then using nested loops to fix the first two elements, and applying the two-pointer technique to find the optimal third and fourth elements. At each step, we track the difference between the current quadruplet sum and the target, keeping the closest sum found so far. Algorithm Steps Sort the ...

Read More

How to generate pascals triangle for the given number using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 183 Views

Pascal's Triangle is a triangular number pattern where each number is the sum of the two numbers directly above it. The triangle starts with 1 at the top, and each row begins and ends with 1. Pascal's Triangle has many applications in mathematics, statistics, and combinatorics, particularly for calculating binomial coefficients and combinations. Each row represents the coefficients of the binomial expansion (a + b)^n, where n is the row number starting from 0. The triangle demonstrates beautiful mathematical properties and patterns that make it useful in various computational problems. Pascal's Triangle (5 rows) ...

Read More

How to check whether you are connected to Internet or not in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

There are several ways to check whether a machine is connected to the internet in C#. The most common approach uses the System.Net namespace, which provides methods for sending and receiving data from resources identified by a URI. The WebClient or HttpClient classes are particularly useful for this purpose. The technique involves making a request to a reliable URL and checking if the response is successful. Google's http://google.com/generate_204 endpoint is commonly used because it returns a minimal response, making it efficient for connectivity checks. Using WebClient for Internet Connectivity Check Example using System; using System.Net; ...

Read More

How to move all the zeros to the end of the array from the given array of integer numbers using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 792 Views

Moving zeros to the end of an array is a common programming problem that can be solved efficiently using a two-pointer approach. The algorithm maintains the relative order of non-zero elements while shifting all zeros to the end of the array. Algorithm Overview The solution uses a single pass through the array with two pointers − Write Pointer − tracks the position where the next non-zero element should be placed Read Pointer − traverses through all elements in the array Time Complexity − O(N) where N is the array length Space Complexity − O(1) ...

Read More

How do I overload the [] operator in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 385 Views

The indexer ([] operator) in C# allows an object to be accessed like an array using square bracket notation. When you define an indexer for a class, instances of that class behave like virtual arrays, enabling array-style access using the [] operator. Indexers can be overloaded with different parameter types and counts. The parameters don't have to be integers — you can use strings, multiple parameters, or any other type as the index. Syntax Following is the basic syntax for defining an indexer − public returnType this[indexType index] { get { ...

Read More
Showing 1–10 of 1,958 articles
« Prev 1 2 3 4 5 196 Next »
Advertisements