Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Data Structure Articles
Found 1,635 articles
JavaScript Program to Find Longest Common Prefix Using Word by Word Matching
Prefixes are substrings that start from the zeroth index of a string and can be of any size from 1 to the complete length of the string. We are given a set of strings and need to find the longest common prefix among all of them using JavaScript. We'll implement word-by-word matching approach where we compare characters at the same position across all strings. Input arr = ["zefkefgh", "zefkdefij", "zeffdzy", "zefkdabacd"]; Output zef Explanation From all the given strings, the first three ...
Read MoreJavaScript Program to Find Minimum Insertions to Form a Palindrome
We are given a string and we have to find the minimum number of characters that we need to insert at any position to make the string a palindrome. A palindrome is a string that reads the same forwards and backwards. This problem can be solved using dynamic programming - we'll explore three approaches: recursive, memoization, and tabulation. Understanding the Problem For example, to make "abc" a palindrome, we need to insert 2 characters to get "abcba" or "cbabc". The key insight is that if characters at both ends match, we can focus on the substring between them. ...
Read MoreJavascript Program to Minimize Characters to be Changed to make the Left and Right Rotation of a String Same
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 MoreMaximum count of characters that can replace ? by at most A 0s and B 1s with no adjacent duplicates
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 MorePosition of the leftmost set bit in a given binary string where all 1s appear at the end
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 Morelargest string formed by choosing words from a given Sentence as per given Pattern
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 MoreFind the count of Alphabetic and Alphanumeric strings from given Array of Strings
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 MoreCount of sum of “10” subsequences for each 1 in string with A 1s, B 10s and C 0s
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 MoreConvert a string Str1 to Str2 by moving B to right and A to left without crossover
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 MoreC Program to Find Minimum Insertions to Form a Palindrome
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