Category Archives: Hash

Distinct strings with odd and even changes allowed

Given an array of lower case strings, the task is to find the number of strings that are distinct. Two strings are distinct if on applying the following operations on one string the second string cannot be formed. A character on odd index can be swapped with another character at odd index only. A character… Read More »

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 »

Count Substrings with equal number of 0s, 1s and 2s

Given a string which consists of only 0s, 1s or 2s, count the number of substrings that have equal number of 0s, 1s and 2s. Examples: Input : str = “0102010” Output : 2 Explanation : Substring str[2, 4] = “102” and substring str[4, 6] = “201” has equal number of 0, 1 and 2… Read More »

Count maximum points on same line

Given N point on a 2D plane as pair of (x, y) co-ordinates, we need to find maximum number of point which lie on the same line. Examples: Input : points[] = {-1, 1}, {0, 0}, {1, 1}, {2, 2}, {3, 3}, {3, 4} Output : 4 Then maximum number of point which lie on… Read More »

Group Shifted String

Given an array of strings (all lowercase letters), the task is to group them in such a way that all strings in a group are shifted versions of each other. Two string S and T are called shifted if, S.length = T.length and S[i] = T[i] + K for 1 <= i <= S.length for… Read More »

Palindrome Substring Queries

Given a string and several queries on the substrings of the given input string to check whether the substring is a palindrome or not. Examples : Suppose our input string is “abaaabaaaba” and the queries- [0, 10], [5, 8], [2, 5], [5, 9] We have to tell that the substring having the starting and ending… Read More »

Print all subarrays with 0 sum

Given an array, print all subarrays in the array which has sum 0. Examples: Input: arr = [6, 3, -1, -3, 4, -2, 2, 4, 6, -12, -7] Output: Subarray found from Index 2 to 4 Subarray found from Index 2 to 6 Subarray found from Index 5 to 6 Subarray found from Index 6… Read More »