Number of subsets with product less than or equals to K | Recently Asked in Morgan Stanley

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
Solve this question on our practice portal:

๐™๐™ค๐™ก๐™ก๐™ค๐™ฌ ๐™ช๐™จ ๐™ค๐™ฃ ๐™ค๐™ช๐™ง ๐™Ž๐™ค๐™˜๐™ž๐™–๐™ก ๐™ˆ๐™š๐™™๐™ž๐™– ๐™ƒ๐™–๐™ฃ๐™™๐™ก๐™š๐™จ -
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

where this is used in company production in last 10 years.

rabindrapatra
ะะฒั‚ะพั€

sir how we calculated the product of elements and pushed them into subset1 and subset2 that i was able to get otherwise sir it was really helpful

nikkimittal
ะะฒั‚ะพั€

maybe would have been better to start with an arbitrary K, say 11, and then exhaustively checking the product of each of the 16 subsets, listing the ones that had product <= 11. I guess empty set has "product" = 0 or do you just ignore it?

MyOneFiftiethOfADollar
ะะฒั‚ะพั€

I am not getting why you guys uploading a bigger stream of the same question where u have discussed this in very detail but now it's deleted why?

MilindGupta
ะะฒั‚ะพั€

I have some doubts:
1. Why in example 1 there's no (3, 3).
2. How single elements give product less than 12 as there's no 1 in given elements.

omkarpachore
ะะฒั‚ะพั€

What is the time and space complexity of this time? if it's in N^2, it can be done in a few lines as below:

public static int NumberOfSubsets(int[] arr, int k)
{
int numberOfSubsts = 0;

Console.Write("Subsets are:");

for (int i = 0; i < arr.Length; i++)
{
if (i <= k)
{
Console.Write($" ({arr[i]}), ");
numberOfSubsts++;
}

for (int j = i+1; j < arr.Length; j++)
{
if (arr[i] * arr[j] <= k)
{
Console.Write($" ({arr[i]}, {arr[j]}), ");
numberOfSubsts++;
}
}
}

return numberOfSubsts;
}

abidalinu