Csharp Articles

Page 9 of 196

How to return the index of first unique character without inbuilt functions using C#?

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

Finding the index of the first unique character in a string is a common programming problem. The approach involves using a frequency array to count character occurrences, then traversing the string again to find the first character with a count of 1. The algorithm uses an array of size 256 to accommodate all ASCII characters. First, we count the frequency of each character, then we find the first character that appears exactly once. Algorithm Steps The solution follows these steps − Create an integer array of size 256 to store character frequencies ...

Read More

How to find the minimum number of jumps required to reach the end of the array using C#?

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

The minimum number of jumps problem involves finding the least number of jumps required to reach the end of an array, where each element represents the maximum number of positions you can jump forward from that index. Given an array where each element represents the maximum jump length from that position, we need to find the minimum jumps to reach the last index. For example, in array {1, 3, 6, 3, 2, 3, 6, 8, 9, 5}, we can reach the end in 4 jumps. Jump Path Visualization 1 ...

Read More

How to rotate a matrix of size n*n to 90-degree k times using C#?

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

Rotating a matrix by 90 degrees is a common operation in programming. When we need to rotate a matrix k times, we can optimize by noting that 4 rotations return the matrix to its original state. Therefore, we only need to perform k % 4 rotations. The algorithm works by processing concentric squares within the matrix. For an n×n matrix, there are n/2 concentric squares. In each square, elements move in a cycle of 4 positions during a 90-degree clockwise rotation. 90° Clockwise Rotation Pattern Original ...

Read More

How to print a matrix of size n*n in spiral order using C#?

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

Printing a matrix in spiral order means traversing the matrix elements layer by layer from the outermost to the innermost layer. We start from the top-left corner and move in a clockwise direction: right, down, left, and up, then repeat for the inner layers. Algorithm Steps Step 1 − Print all elements of the top row from left to right Step 2 − Print all elements of the rightmost column from top to bottom Step 3 − Print all elements of the bottom row from right to left Step 4 − Print all elements of the leftmost ...

Read More

How to print number of islands in a given matrix using C#?

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

An island in a matrix is a group of connected cells containing '1' (representing land) that are surrounded by '0' (representing water). Two cells are considered connected if they are adjacent horizontally or vertically. This problem uses Depth-First Search (DFS) to traverse and mark all connected land cells as visited. The algorithm performs a linear scan of the 2D grid. When it finds a '1' that hasn't been visited, it triggers a DFS to explore the entire connected island and marks all cells in that island as visited. Each DFS call represents one complete island. Algorithm Steps ...

Read More

How to find all the permutation of the string by backtracking using C#?

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

String permutation using backtracking is a classic algorithm that generates all possible arrangements of characters in a string. The approach works by fixing one character at a time and recursively finding permutations of the remaining characters, then backtracking to explore other possibilities. The core idea is to swap characters systematically − fix the first position with each character, find permutations of the rest, then backtrack by undoing the swap to try the next possibility. Backtracking Process for "ABC" ABC ...

Read More

How to get all the combinations of the keypad value in a mobile by backtracking using C#?

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

The problem of generating all possible letter combinations from mobile keypad digits can be solved efficiently using backtracking. This approach explores all possible paths by making choices, exploring them recursively, and backtracking when a complete combination is formed. On a traditional mobile keypad, each digit from 2-9 corresponds to a set of letters. The goal is to find all possible combinations when given a sequence of digits. Mobile Keypad Mapping 2 ABC 3 DEF 4 ...

Read More

How to find the target sum from the given array by backtracking using C#?

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

The target sum problem involves finding all possible combinations from a given array where the sum of elements equals a specific target value. The backtracking approach systematically explores all possible combinations by adding elements to the current solution and removing them when they don't lead to a valid result. Given an array of positive integers and a target sum, we need to find all combinations where elements can be reused and their sum equals the target. For example, with array [1, 2, 3] and target 4, valid combinations are [1, 1, 1, 1], [1, 1, 2], [1, 3], and ...

Read More

How to find the distinct subsets from a given array by backtracking using C#?

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

The distinct subsets problem involves finding all unique combinations of a specific size from a given array using backtracking. This technique systematically explores all possible combinations by adding elements to the current subset and then removing them to explore other possibilities. When we specify a target size, the algorithm generates all combinations that contain exactly that many elements. For example, with array [1, 2, 3] and target size 2, we get combinations "1, 2", "1, 3", and "2, 3". How Backtracking Works for Subsets The backtracking algorithm follows these steps − Choose − Add an ...

Read More

How to find all the different combinations of opening and closing brackets from the given number k using C#?

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

Finding all valid combinations of opening and closing brackets for a given number k is a classic backtracking problem in computer science. This problem generates all possible arrangements of k pairs of brackets where each opening bracket has a corresponding closing bracket in the correct order. The solution uses a recursive backtracking approach that builds valid bracket combinations by placing opening brackets when available and closing brackets only when they don't exceed the number of opening brackets already placed. Algorithm Overview The backtracking algorithm follows these key rules − Add an opening bracket if ...

Read More
Showing 81–90 of 1,951 articles
« Prev 1 7 8 9 10 11 196 Next »
Advertisements