Techno Blender
Digitally Yours.
Browsing Tag

Equal

Two nodes in a Linked list whose product is equal to the target value

Improve Article Save Article Like Article Improve Article Save Article Given a head of a singly linked list and a target value. The task is to find whether there exist any two nodes in the linked list whose product is equal to the target value.Examples:Input:  Linked-List =  2->5->3->4->6, Target = 12Output: TrueInput: Linked-List = 1->4->3->7->2, Target = 5Output: FalseApproach: This can be solved with the following idea:Using the Set data structure, check if the target is divided by a value…

Find that the value of 2^{2n} is equal to O(2^n) or not

Improve Article Save Article Like Article Improve Article Save Article Given an integer n, the task is to find that the value of 2^{2n} is equal to O(2^n) or not.Examples: Input: n = 2Output: TrueInput: n = 3Output: FalseProof for the above equation:We say that f(x) = O(g(x)) if and only if there exist positive constants c and k such that |f(x)| ≤ c|g(x)| for all x ≥ k. So, We need to find constants c and n0 such that |2^{2n}| ≤ c|2^n| for all n > n0.Using the properties of exponents, we can rewrite 2^{2n} as…

Equal number of 0’s and 1’s

Given two numbers a and b. Find the minimum number of steps required to make the number of the set (1) and unset(0) bits equal in a, b, and a ^ b where you can perform the following operations:convert a = a ^ p, p is some numberconvert b = b ^ q, q is some numberExamples:Input: a = 10, b = 12output: 0Explanation:in a, number of bits containing 0 = 2 and number of bits containing 1 = 2in b, number of bits containing 0 = 2 and number of bits containing 1 = 2x = a ^ b = 0110, So no conversion is needed clearly, no p, q is…

Minimum cost to make every Kth element in Array equal

Given an array arr of integers and an integer K, the task is to find the minimum number of operations required to make every Kth element in the array equal. While performing one operation you can either increase a number by one or decrease the number by one.Examples:Input: arr = {1, 2, 3, 4, 4, 6}, K = 3Output: 8Explanation: For the given array, value of K = 3 which means every 3rd element in the array should be equal. So we have to make 1 = 4, 2 = 4 and 3 = 6. So by performing 3 operations on 1 we can make it equal to 4…

Find the longest Subarray with equal Sum and Product

Given an array arr of N integers, the task is to find the length of the longest subarray where the sum of the elements in… Read More The post Find the longest Subarray with equal Sum and Product appeared first on GeeksforGeeks. Given an array arr of N integers, the task is to find the length of the longest subarray where the sum of the elements in… Read More The post Find the longest Subarray with equal Sum and Product appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original article here Denial…

Split Strings into two Substrings whose distinct element counts are equal

Improve Article Save Article Like Article Improve Article Save Article Given a string S of length N, the task is to check if a string can be split into two non-intersecting strings such that the number of distinct characters are equal in both.Examples:Input: N = 6, S = “abccba”Output: TrueExplanation: Splitting two strings as “abc” and “cba” has 3 distinct characters each.Input: N = 5, S = “aacaa”Output: FalseExplanation: Not possible to split it into two strings of the same distinct characters.Approach: To solve the…

Min operations for each index to make element at that cell equal to 1

Given a matrix M having R rows and C columns, the task is to return a matrix X in which X represents the number of… Read More The post Min operations for each index to make element at that cell equal to 1 appeared first on GeeksforGeeks. Given a matrix M having R rows and C columns, the task is to return a matrix X in which X represents the number of… Read More The post Min operations for each index to make element at that cell equal to 1 appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original…

Max length of common interval whose Bitwise OR, AND are equal in both Arrays

#include <bits/stdc++.h>using namespace std;  int orCalculate(int st, int length,                vector<vector<int> >& bitPrefix){    int val = 0;    for (int j = 0; j < 32; j++) {        int cnt            = bitPrefix - bitPrefix;        if (cnt != 0)                                                  val += (1 << j);    }    return val;}  int andCalculate(int st, int length,                 vector<vector<int> >& bitPrefix){    int val = 0;    for (int j = 0; j < 32; j++) {…

Print all Substrings of a String that has equal number of vowels and consonants

Improve Article Save Article Like Article Improve Article Save Article Given a string S, the task is to print all the substrings of a string that has an equal number of vowels and consonants.Examples:Input: “geeks”Output: “ge”, “geek”, “eeks”, “ek”Input: “coding”Output: “co”, “codi”, “od”, “odin”, “di”, “in”Naive Approach: The basic approach to solve this problem is to generate all the substrings and then for each substring count the number of vowels and consonants present in it. If they are equal print it. Time…

Number of ways whose sum is greater than or equal to K

Given an array, arr, and an integer K, the task is to find the total number of ways in which we can divide the array into two groups such that the sum of each group is greater than equal to K and each element belongs to one of these groups.Examples:Input: arr = , K = 2Output: 2Explanation: The partitions are (, ) and (, ) since both the 6 at index 0 and 1 are treated differently.Input: arr = , K = 4Output: 6Explanation: The partitions are: (, ), (, ), (, ), (, ), (, ) and (, ).Approach: The problem can be solved based on…