Tag Archives: subset

Largest divisible subset in array

Given an array the task is to largest divisible subset in array. A subset is called divisible if for every pair (x, y) in subset, either x divides y or y divides x. Examples: Input : arr[] = {1, 16, 7, 8, 4} Output : 16 8 4 1 In the output subset, for every… Read More »

Subset sum queries using bitset

Given an array arr[] and a number of queries, where in each query we have to check whether a subset whose sum is equal to given number exists in the array or not. Examples: Input : arr[] = {1, 2, 3}; query[] = {5, 3, 8} Output : Yes, Yes, No There is a subset… Read More »

Chocolate Distribution Problem

Given an array of n integers where each value represents number of chocolates in a packet. Each packet can have variable number of chocolates. There are m students, the task is to distribute chocolate packets such that : Each student gets one packet. The difference between the number of chocolates in packet with maximum chocolates… Read More »