Saturday, 23 Oct 2021

We are living in a digital world that is completely driven by chunks of code. Every industry depends on software for its proper functioning be it healthcare, military, banking, research, and the list goes on. We have a huge list of programming languages that facilitate the software development process. One of these is Python which […]

Given 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 […]

Given an array arr[] of size N, the task is to find the value of an integer K such that its repeated subtraction from array elements will make all array elements in minimum operations.Example:Input: arr[] = {5, 3, 3, 7}Output: 2Explanation: Minimum 2 operations must be performed:1st operation: subtract 2 from elements at indices {0, […]

Given integers N and K, the task is to check if a number can be represented as the sum of numbers that have at least one digit equal to K.Example:Input: N = 68, K = 7Output: YESExplanation: 68 = (27 + 17 + 17 + 7). Each number has atleast one digit equal to 7.Input: […]

Given an array arr[] of size N, the task is to find the minimum number of operations required to make all array elements zero. In one operation, select a pair of elements and subtract the smaller element from both elements in the array.Example:Input: arr[] = {1, 2, 3, 4}Output: 3Explanation: Pick the elements in the […]

Given 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”, […]

Given an array arr[] of size N and an integer X, the task is to find the length of the longest subsequence such that the prefix sum at every element of the subsequence remains greater than zero.Example:Input: arr[] = {-2, -1, 1, 2, -2}, N = 5Output: 3Explanation: The sequence can be made of elements […]

Given three integers A, B, and K. The task is to check whether A and B can be reduced to zero by decrementing x and y from A and B respectively such that abs(x – y) ≤ K.Example:Input: A = 2, B = 7, K = 3Output: YESExplanation: Decrement values in the following way:Decrement 1 […]

def findHiddenMissing(arr1, arr2, N):            arr1.sort()    arr2.sort()        mp = {}            for i in range(0, N – 1):                                                               a = arr2[i] – arr1[i]                                b = arr2[i] – arr1[i + 1]                if (a != b):                                    if (a > 0):                if not a in mp:                    mp[a] = 1                else:                    mp[a] += 1                                if (b > 0):                if not b in mp:                    mp[b] = 1                else:                    mp[b] += 1                        else:                                    if (a > 0):                if not a in mp:                    mp[a] = […]

#include using namespace std;int minDeques(vector arr){            vector fronts, backs;        for (int i = 0; i < arr.size(); i++) {                        bool hasBeenPushed = false;        for (int j = 0; j < fronts.size(); j++) {                                    if (arr[i] < fronts[j]) {                bool isSafe = true;                for (int k = 0; k < arr.size(); k++) {                    if (arr[i] < arr[k]                        && arr[k] < fronts[j]) {                        isSafe = false;                        break;                    }                }                                                if (isSafe) […]