Data Structure Articles

Page 2 of 164

Javascript Program to Minimize Characters to be Changed to make the Left and Right Rotation of a String Same

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 167 Views

In this problem, we need to find the minimum number of character changes required to make a string's left and right rotations identical. This involves understanding how rotations work and finding patterns in character positioning. Understanding Rotations The left rotation moves characters left by one position, while right rotation moves them right. For rotations to be identical, specific character patterns must exist: Odd length strings: All characters must be the same Even length strings: Characters at even positions must be identical, and characters at odd positions must be identical Problem Analysis Given a ...

Read More

Maximum count of characters that can replace ? by at most A 0s and B 1s with no adjacent duplicates

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 806 Views

In this problem, we need to replace '?' characters in a string with '0's and '1's such that no two adjacent characters are the same, while maximizing the number of replacements using at most A zeros and B ones. Syntax int maximumChar(char *str, int aCount, int bCount); Problem Statement Given a string containing '*' and '?' characters, and two integers A and B representing available 0s and 1s, find the maximum number of '?' characters that can be replaced without creating adjacent duplicates. Algorithm The approach involves the following steps − ...

Read More

Position of the leftmost set bit in a given binary string where all 1s appear at the end

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 430 Views

The aim of this article is to implement a program to find the position of the leftmost set bit in a given binary string where all 1s appear at the end. A binary string is a sequence of bits (0s and 1s) used to represent data in binary format. In this problem, we are given a binary string where all the 1s are grouped together at the rightmost positions, and we need to find the leftmost position where the first '1' appears. Syntax int findFirstBit(char* str, int length); Problem Statement Given a binary ...

Read More

largest string formed by choosing words from a given Sentence as per given Pattern

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 407 Views

To find the largest string formed by choosing words from a given sentence, a user should know about the lexicographically largest string. A lexicographically largest string is a string, when sorted alphabetically, it would appear at the last if we form all possible strings from the selected words. For example: {lion, zebra, apple} will be lexicographically sorted as {apple, lion, zebra}. In this article, we have been given a string and a pattern. Based on this pattern, we have to find the lexicographically largest string matching the given pattern by choosing words from the sentence using C. Here is ...

Read More

Find the count of Alphabetic and Alphanumeric strings from given Array of Strings

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 507 Views

In C programming, counting alphabetic and alphanumeric strings from an array involves checking each character in every string. An alphabetic string contains only letters (a-z, A-Z), while an alphanumeric string contains both letters and digits (0-9). Syntax int isAlphabetic(char str[]); int isAlphanumeric(char str[]); void countStrings(char arr[][MAX_LEN], int n); Algorithm The approach to solve this problem involves the following steps − Step 1 − Iterate through each string in the array Step 2 − Check each character to determine if string is alphabetic or alphanumeric Step 3 − Count occurrences and maintain frequency ...

Read More

Count of sum of “10” subsequences for each 1 in string with A 1s, B 10s and C 0s

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 290 Views

In C programming, we need to find the count of "10" subsequences for each '1' in a string that contains A individual 1s, B "10" substrings, and C individual 0s. This problem involves counting subsequences where each '1' can pair with available '0' characters. Syntax long long maximumSubSeq(int A, int B, int C); Problem Understanding Given three parameters − A − Number of standalone '1' characters B − Number of "10" substrings C − Number of standalone '0' characters We need to count all possible "10" subsequences from the concatenated string. ...

Read More

Convert a string Str1 to Str2 by moving B to right and A to left without crossover

Thanweera Nourin A V
Thanweera Nourin A V
Updated on 15-Mar-2026 301 Views

The aim of this article is to implement a program to convert a string Str1 to Str2 by moving B to right and A to left without crossover. In this problem, we have two strings where characters 'A' can only move left, characters 'B' can only move right, and empty spaces are represented by '#'. The key constraint is that 'A' and 'B' characters cannot cross over each other during movement. Syntax bool moveRobots(char str1[], char str2[]); Examples Example 1 Input: str1 = "#B#A#", str2 = "##BA#" Output: Yes ...

Read More

C Program to Find Minimum Insertions to Form a Palindrome

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 515 Views

A palindrome is a string that reads the same forwards and backwards. Given a string, we need to find the minimum number of character insertions required to make it a palindrome. We will explore three approaches − recursive, memoization, and dynamic programming. Syntax int minInsertions(char str[], int start, int end); Method 1: Recursive Approach The recursive approach compares characters from both ends. If they match, we move inward; otherwise, we try inserting at either end and take the minimum ? #include #include #include int findMin(int a, int b) ...

Read More

PHP Program for Converting Roman Numerals to Decimal Lying Between 1 to 3999

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 326 Views

Roman numerals are characters used in a numeric notation system based on the ancient Roman system. In this tutorial, we'll convert Roman numeral strings to decimal values in the range 1 to 3999. Roman Numeral System Roman numerals follow descending order but use subtractive notation to avoid four consecutive characters. Here are the main symbols − SYMBOL VALUE M 1000 CM 900 D 500 CD 400 C 100 XC 90 L 50 XL 40 X 10 ...

Read More

PHP Program to Check if all rows of a matrix are circular rotations of each other

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 212 Views

A rectangular array called a matrix is made up of rows and columns. And circular rotations entail rotating the array's elements so that after one rotation, the last member is in the first position and the other elements are shifted to the right. We are given an N*N matrix in this problem, and our objective is to determine whether all of the rows are circular rotations of one another. If they are, print "YES, " otherwise print "NO." In order to better understand the issue, let's look at some cases with explanations below. Input 1 mat ...

Read More
Showing 11–20 of 1,635 articles
« Prev 1 2 3 4 5 164 Next »
Advertisements