Given three strings A, B, and C of equal length, the task is to find the minimum number of replacement operations that can be performed such that any two out of the three strings become equal.Examples: Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course […]

Continue Readingimport java.io.*;import java.util.*;class Main { static void print(char ch[]) { for (Character c : ch) { System.out.print(c); } System.out.println(); } static boolean check(char ch[]) { Stack S = new Stack(); if (ch[0] == ‘)’) { return false; } for (int i = 0; i < ch.length; i++) { if (ch[i] == '(') { S.add('('); } else { if (S.size() == 0) return false; else S.pop(); } } if (S.size() == 0) return true; else return false; } static void count(char ch[], int index) { if (index == […]

Continue ReadingGiven a binary array arr[] and an integer K, the task is to count the maximum number of 0’s that can be flipped to 1’s such that there are at least K 0’s between two 1’s.Example:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course […]

Continue ReadingGiven a string s. The task is to minimize the number of adjacent swaps required to reverse the string. Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to […]

Continue ReadingGiven three integers a, b and c which denotes the frequencies of three different characters ‘A‘, ‘B‘, and ‘C‘ respectively, and can be used to form strings of length 3. The task is to count the total number of possible combinations of A, B and C such that it forms a string having at least […]

Continue ReadingGiven two integers N and K, the task is to find the count of binary strings of at most N length that can be formed such that the count of consecutive 1‘s is always a multiple of K.Example:Input: N = 3, K = 2Output: 6Explanation: Binary strings of atmost N length containing consecutive 1’s as […]

Continue ReadingGiven string str that contains only digits, the task is to return an expression by inserting the ‘+’ or ‘*’ operator between every two digits such that the arithmetic value of the expression is minimized.Example: Input: str = “322”Output: “3+2*2”Explanation: The value of above expression is 7 which is minimum possible over the other expressions “3+2+2”, […]

Continue Reading#include using namespace std; void minSwapsKthLargest(string str, int k){ string res = str; for (int i = 0; i < k; i++) { next_permutation( str.begin(), str.end()); } int swap_count = 0; for (int i = 0; i < res.length(); i++) { if (res[i] != str[i]) { int start = i + 1; while (res[i] != str[start]) { start++; } while (i != start) { swap(str[start], str[start - 1]); start--; swap_count++; } } } cout

Continue Reading#include #define SIZE 100005using namespace std; void preprocess(string& s, string& t, int prefix[][SIZE], int n, int i){ prefix[i][0] = (s[0] != t[0]); for (int j = 1; j < n; j++) { prefix[i][j] = prefix[i][j - 1] + (s[j] != t[j % 3]); } return;} void minChangesNonPalindrome( string str, int N, int Q, vector queries){ int prefix[6][SIZE]; vector sequences = { "012", "021", "102", "120", "201", "210" }; for (int i = 0; […]

Continue Reading#include using namespace std; string findSum(string str1, string str2){ if (str1.length() > str2.length()) swap(str1, str2); string str = “”; int n1 = str1.length(); int n2 = str2.length(); reverse(str1.begin(), str1.end()); reverse(str2.begin(), str2.end()); int carry = 0; for (int i = 0; i < n1; i++) { int sum = ((str1[i] - '0') + (str2[i] - '0') + carry); str.push_back(sum % 10 + '0'); carry = sum / 10; } for (int i = n1; […]

Continue Reading