Queries to find the minimum array sum possible by removing elements from either end
Given an array arr[] consisting of N distinct integers and an array Q[] representing queries, the task for every query Q[i] is to find the minimum sum possible by removing the array elements from either end until Q[i] is obtained....
read more
Number of subarrays having sum of the form k^m, m >= 0
Given an integer k and an array arr[], the task is to count the number of sub-arrays that have the sum equal to some positive integral power of k.Examples:...
read more
Count substrings consisting of equal number of a, b, c and d
Given a string str, the task is to count non-empty substrings with equal number of ‘a’, ‘b’, ‘c’, and ‘d’....
read more
Maximum repeated frequency of characters in a given string
Given a string S, the task is to find the count of maximum repeated frequency of characters in the given string S.Examples:...
read more
Queries to find index of Kth occurrence of X in diagonal traversal of a Matrix
Given a matrix A[][] of size N*M and a 2D array Q[][] consisting of queries of the form {X, K}, the task for each query is to find the position of the Kth occurrence of element X in the matrix when the diagonal traversal from left to right is performed. If the frequency of element X in the matrix is less than K, then print “-1”....
read more
Find the k smallest numbers after deleting given elements
Given an array of integers, find the k smallest numbers after deleting given elements. In case of repeating elements delete only one instance in the given array for every instance of element present in the array containing the elements to be deleted....
read more
Minimum count of prefixes and suffixes of a string required to form given string
Given two strings str1 and str2, the task is to find the minimum number of prefixes and suffixes of str2 required to form the string str1. If the task is not possible, return “-1”....
read more
Sum of Bitwise AND of each array element with the elements of another array
Given two arrays arr1[] of size M and arr2[] of size N, the task is to find the sum of bitwise AND of each element of arr1[] with the elements of the array arr2[]....
read more
Longest Common Subsequence of two arrays out of which one array consists of distinct elements only
Given two arrays firstArr[], consisting of distinct elements only, and secondArr[], the task is to find the length of LCS between these 2 arrays....
read more
Interesting interview question on hashCode and equals method
Prerequisite: Equal and Hashcode Methods in Java , Why to override equal and hashcode methods...
read more
Use of FLAG in programming
Flag variable is used as a signal in programming to let the program know that a certain condition has met. It usually acts as a boolean variable indicating a condition to be either true or false. Example 1: Check if an array has any even number....
read more
Find sum of all unique elements in the array for K queries
Given an arrays arr[] in which initially all elements are 0 and another array Q[][] containing K queries where every query represents a range [L, R], the task is to add 1 to each subarrays where each subarray is defined by the range [L, R], and return sum of all unique elements.Note: One-based indexing is used in the Q[][] array to signify the ranges.Examples:...
read more