Tag: STL

Print all combination of numbers from 1 to n having sum n

Given a positive integer n, print all combination of numbers from 1 to n having sum n. Get great deals at Amazon

Replace each element of the array by its corresponding rank in the array

Given an array of distinct integers, replace each element of the array by its corresponding rank in the array.

Find all common elements present in every row of given matrix

Given a M x N matrix, find all common elements present in every row.

Group elements of an array based on their first occurrence

Given an unsorted array of integers containing many duplicates elements, rearrange the given array such that same element appears together and relative order of first occurrence of each element remains unchanged.

Find maximum absolute difference between sum of two non-overlapping sub-arrays

Given an array, find the maximum absolute difference between sum of elements of two non-overlapping sub-arrays in linear time.

Find all Symmetric Pairs in an Array of Pairs

Given an array of pairs of integers, find all symmetric pairs i.e. pairs that are mirror of each other. For instance, pairs (x, y) and (y, x) are mirrors of each other.

Construct the longest palindrome by shuffling or deleting characters from a string

Write a efficient algorithm to construct the longest palindrome by shuffling or deleting characters from a given string.

Find count of distinct elements in every sub-array of size k

Given an array and an integer k, find the count of distinct elements in every sub-array of size k in the array.

Determine if characters of a String follows a specified order or not

Given a string and a pattern (having all distinct characters), determine if characters of the string follows specific order as defined by characters of the pattern.

Find two numbers with maximum sum formed by array digits

Given an array of integers between 0 to 9, find two numbers with maximum sum formed by using all digits of the array. The difference in number of digits of the two numbers should be ± 1.

Print all sub-arrays of an array having distinct elements

Given an array of integers, print all maximum size sub-arrays having all distinct elements in them.

Find ways to calculate a target from elements of specified array

Write a program to count number of ways to calculate a target number from elements of specified array by using only addition and subtraction operator. The use of any other operator is forbidden.