Csharp Articles

Page 69 of 196

What is the purpose of the StringBuilder class in C#?

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 591 Views

In C#, strings are immutable, meaning you cannot modify a string once it's created. Any modification returns a new string containing the changes, leaving the original intact. The StringBuilder class provides a mutable alternative for efficient string manipulation when you need to perform multiple modifications. String Immutability Example using System; class Program { static void Main(string[] args) { string word = "aaabbbccc"; string newWord = word.Replace('b', 'd'); Console.WriteLine(word); ...

Read More

System.Reflection namespace in C#

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 688 Views

The System.Reflection namespace in C# provides classes and interfaces that allow you to examine and interact with assemblies, modules, types, and members at runtime. This powerful feature enables reflection — the ability to inspect and manipulate code dynamically during execution. The Assembly class is central to this namespace, representing a loaded assembly in memory. You can access an assembly through a type's Assembly property or load it dynamically using various methods. Assembly Identity Components An assembly's identity consists of four key components − Simple name − the filename without the extension Version − from the ...

Read More

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

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

A row-wise and column-wise sorted matrix has elements arranged in ascending order both horizontally (across rows) and vertically (down columns). This creates a special structure that allows for efficient searching algorithms beyond simple linear traversal. The most straightforward approach is to treat the sorted 2D matrix as a flattened 1D array and apply binary search. Since elements maintain sorted order when concatenated row by row, we can use index mapping to convert 1D positions back to 2D coordinates. Syntax Following is the syntax for converting between 1D and 2D indices in a matrix − // ...

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 460 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 unique triplet that is close to the given target using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 295 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 310 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 209 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 check whether the given strings are isomorphic using C#?

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

Two strings are called isomorphic if there exists a one-to-one character mapping between them. This means each character in the first string maps to exactly one character in the second string, and no two characters can map to the same character. The mapping must be consistent throughout both strings. For example, "egg" and "add" are isomorphic because 'e' maps to 'a', and 'g' maps to 'd'. However, "foo" and "bar" are not isomorphic because 'o' would need to map to both 'a' and 'r'. Algorithm Approach The solution uses two arrays to track the last seen position ...

Read More

How to find the length of the longest continuous increasing subsequence from an array of numbers using C#?

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

The Longest Continuous Increasing Subsequence problem finds the length of the longest subarray where elements are in strictly increasing order. This algorithm uses a single pass through the array to track the current sequence length and maintains the maximum length found so far. The approach uses two variables: count to track the current increasing sequence length and res to store the maximum length encountered. When an element breaks the increasing pattern, the count resets to 1. Algorithm Explanation The algorithm works as follows − Initialize count = 1 and res = 1 to handle ...

Read More

How to implement Fibonacci using topDown approach using C#?

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

The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. The top-down approach focuses on breaking down a big problem into smaller and understandable chunks using memoization to store previously computed values. This approach uses recursion with an additional array to cache results, avoiding redundant calculations and significantly improving performance over naive recursion. Complexity Analysis Time complexity − O(N) because each Fibonacci number is ...

Read More
Showing 681–690 of 1,951 articles
« Prev 1 67 68 69 70 71 196 Next »
Advertisements