Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 7 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 621 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 423 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 the unique combination k sum that corresponds to k sum using C#?

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

The k-sum combination problem involves finding all unique combinations of exactly k numbers from a given range that sum up to a specific target value. This is solved using backtracking, which explores all possible combinations while pruning invalid paths early. The algorithm maintains two lists: an output list to store valid combinations and a currentList to track the current combination being explored. The backtracking function recursively explores combinations, adding numbers one by one until either the target sum is achieved with exactly k numbers, or the constraints are violated. How It Works The backtracking algorithm follows these ...

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 454 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

How to find the minimum number of steps needed by knight to reach the destination using C#?

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

In chess, a knight moves in an L-shape − two squares in one direction and one square perpendicular to that. This article explains how to find the minimum number of steps (moves) needed for a knight to reach a destination cell on a chessboard using Breadth-First Search (BFS) algorithm in C#. The knight's movement pattern creates a shortest path problem that can be efficiently solved using BFS, as it explores all possible moves level by level, guaranteeing the minimum number of steps. Knight's Movement Pattern A knight can move to at most 8 positions from any given ...

Read More

How to find the number of times array is rotated in the sorted array by recursion using C#?

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

To find the number of times a sorted array has been rotated, we need to locate the position of the minimum element. The number of rotations equals the index of the minimum element. We can solve this efficiently using binary search recursion. In a rotated sorted array, the minimum element is the pivot point where the rotation occurred. For example, in array [4, 5, 6, 1, 2, 3], the minimum element 1 is at index 3, meaning the array was rotated 3 times. Algorithm The recursive binary search approach works as follows − Find ...

Read More

How to convert XML to Json and Json back to XML using Newtonsoft.json?

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

Newtonsoft.Json (Json.NET) provides powerful methods for converting between XML and JSON formats. The library preserves all XML features including elements, attributes, text content, comments, character data, processing instructions, namespaces, and XML declarations during conversion. Required NuGet Package Install the Newtonsoft.Json package to use these conversion methods − Install-Package Newtonsoft.Json Key Methods The JsonConvert class provides two essential methods for XML-JSON conversion − SerializeXmlNode() − Converts XML to JSON format DeserializeXmlNode() − Converts JSON back to XML format Converting XML to JSON Use SerializeXmlNode() to convert an XmlDocument or ...

Read More

How to copy files into a directory in C#?

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

To copy files in C#, the File.Copy method is the primary approach. This method allows you to copy individual files from one location to another, with options to control whether existing files should be overwritten. Syntax The File.Copy method has two overloads − File.Copy(string sourceFileName, string destFileName) File.Copy(string sourceFileName, string destFileName, bool overwrite) Parameters sourceFileName − The file to copy. destFileName − The name of the destination file. This cannot be a directory. overwrite − true if the destination file should be overwritten if it already exists; otherwise, false. ...

Read More

What is use of fluent Validation in C# and how to use in C#?

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

FluentValidation is a powerful .NET library for building strongly-typed validation rules using a fluent interface and lambda expressions. It helps separate validation logic from your domain models, making your code cleaner and more maintainable by centralizing validation rules in dedicated validator classes. The library provides an intuitive way to define complex validation rules with built-in validators, custom validation methods, and detailed error messaging. It's particularly useful in web applications, APIs, and any scenario where robust input validation is required. Installation To use FluentValidation in your project, install the NuGet package − Syntax ...

Read More

How to valid DateofBirth using fluent Validation in C# if it exceeds current year?

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

FluentValidation in C# provides a powerful way to validate model properties using a fluent interface. When validating date of birth, you need to ensure the date doesn't exceed the current year and falls within a reasonable age range. This validation is essential for preventing future dates in birth date fields and ensuring data integrity in applications dealing with user registration or profile management. Syntax Following is the syntax for creating a date of birth validation rule using FluentValidation − RuleFor(p => p.DateOfBirth) .Must(BeAValidAge) .WithMessage("Invalid {PropertyName}"); ...

Read More
Showing 61–70 of 1,958 articles
« Prev 1 5 6 7 8 9 196 Next »
Advertisements