0% found this document useful (0 votes)
4 views3 pages

Product Recommendation Strategies

The document contains a Java class named Solution that provides methods for cross-selling and up-selling products based on purchased products and inventory. It uses a helper method to recommend products by comparing prices within the same category. The main method demonstrates the functionality with example data for purchased products and inventory, printing the recommended cross-sell and up-sell products.

Uploaded by

nobitakumar5147
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Product Recommendation Strategies

The document contains a Java class named Solution that provides methods for cross-selling and up-selling products based on purchased products and inventory. It uses a helper method to recommend products by comparing prices within the same category. The main method demonstrates the functionality with example data for purchased products and inventory, printing the recommended cross-sell and up-sell products.

Uploaded by

nobitakumar5147
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

class Solution {

public List<String> crossSell(List<String> purchasedProducts,


List<String> inventory) {

return recommendProducts(purchasedProducts, inventory, false);

public List<String> upSell(List<String> purchasedProducts, List<String>


inventory) {

return recommendProducts(purchasedProducts, inventory, true);

private List<String> recommendProducts(List<String>


purchasedProducts, List<String> inventory, boolean isUpSell) {

Map<String, Integer> maxPriceByCategory =


[Link]()

.map(p -> [Link](","))

.collect([Link](p -> p[2],

[Link](

[Link]([Link](p ->
[Link](p[3]))),

opt -> [Link]([Link]()[3])

));

return [Link]()

.map(p -> [Link](","))

.filter(p -> [Link](p[2])


&& (isUpSell ? [Link](p[3]) >
[Link](p[2])

: [Link](p[3]) <=
[Link](p[2])))

.sorted([Link](p -> [Link](p[3])))

.map(p -> [Link](",", p))

.collect([Link]());

public static void main(String[] args) {

Solution solution = new Solution();

List<String> purchasedProducts = [Link]("1,ProductA,Category1,100",


"2,ProductB,Category2,150");

List<String> inventory = [Link]("3,ProductC,Category1,80",


"4,ProductD,Category1,120", "5,ProductE,Category2,160",
"6,ProductF,Category3,90");

List<String> crossSellProducts = [Link](purchasedProducts,


inventory);

[Link]("Cross-sell Products:");

[Link]([Link]::println);

List<String> upSellProducts = [Link](purchasedProducts,


inventory);

[Link]("\nUp-sell Products:");

[Link]([Link]::println);

You might also like