Category Archives: Arrays

Questions regarding Arrays

Count all pairs with given XOR

Given an array of distinct positive integers and a number x, find the number of pairs of integers in the array whose XOR is equal to x. Examples: Input : arr[] = {5, 4, 10, 15, 7, 6}, x = 5 Output : 1 Explanation : (10 ^ 15) = 5 Input : arr[] =… Read More »

Length of Longest sub-string that can be removed

Given a binary string (consists of only 0 and 1). If there is “100” as a sub-string in the string, then we can delete this sub-string. The task is to find the length of longest sub-string which can be make removed? Examples: Input : str = “1011100000100” Output : 6 // Sub-strings present in str… Read More »

Sum of subset differences

Given a set S consisting of n numbers, find the sum of difference between last and first element of each subset. We find first and last element of every subset by keeping them in same order as they appear in input set S. i.e., sumSetDiff(S) = ∑ (last(s) – first(s)), where sum goes over all… Read More »