Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anushshukla/55601a802ae660b7ad3b6b8f6cce5d3f to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/55601a802ae660b7ad3b6b8f6cce5d3f to your computer and use it in GitHub Desktop.
[Draft] Find maximum products which can picked up from pile of products with increasing count of products pick up
const removeProductsFromPile = (pileOfProducts, indexStart = 0, endIndex = pileOfProducts.length, maxProducts, reduceBy = 'max') => {
pileOfProducts.map((product, currentProductIndex) => {
const productsLeftInPile = product - 1;
let lastProductsPickCount;
for (let nextProductIndex = currentProductIndex + 1; nextProductIndex < pileOfProducts.length; nextProductIndex++) {
const nextPileOfProduct = product[nextProductIndex];
if (nextPileOfProduct > product) {
maxProducts = product + nextPileOfProduct;
}
if (nextPileOfProduct < product) {
maxProducts = nextPileOfProduct + nextPileOfProduct - 1;
}
removeProductsFromPile(product)
}
});
return false;
}
function findMaxProducts(pileOfProducts) {
let maxProducts = 0;
maxProducts = removeProductsFromPile(product, 1);
}
function main() {
console.log('Test case passed:', findMaxProducts([2, 9, 4, 7, 5, 2]) === 16)
}
{/* <ul>
<li>Choose subarray from indices (1, 2) and pick&nbsp;products [2, 9] respectively from each index, which is 11 products.</li>
<li>Choose subarray from indices (1, 4) and pick&nbsp;products [2, 3, 4, 7] , which is 16 products.</li>
<li>Choose subarray from indices (1, 5) and pick&nbsp;products [1, 2, 3, 4, 5], which is 15 products.</li>
</ul> */}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment