Skip to main content

Posts

Featured

Coding interview questions set 8

 Let's begin with set 8, 16)If given a max weight as input find out max allocation from a given array of jewelry weights. Example 1: Input: maxWeight=5 weightArray=[5,2,6] output: [{weight:5,qnt:1 }] Example 2: Input: maxWeight=12 weightArray=[5,2,6] output: [{weight:5,qnt:2},{weight:2,qnt:1}] Solution: function findCombination(maxWeight,weightArray) { var myArray = weightArray; let finalArray = []; for (let i = 0 ; i < myArray . length; i ++ ) { let effectiveWeight = myArray[i]; let remainder = maxWeight % effectiveWeight; let quotient = Math . trunc(maxWeight / effectiveWeight); if (quotient > 0 ) { finalArray . push({ weight: myArray[i], qnt: quotient }); } if (remainder == 0 ) { break ; } else { maxWeight = maxWeight - quotient * effectiveWeight; } } return finalArray; } Logic: Here we get quotient and remainder and p

Latest Posts

Node.js interview questions set 1

Rapid fire 28 javascript questions and answers .

Mongodb Basics Set 1: Insert Operation

Coding interview questions set 7

Data structure problem 2 (Stack): Valid Parentheses problem.

Create a multi column csv report in nodejs without external library.

Javascript interview questions set 3

CSS INTERVIEW QUESTIONS SET 2

Coding Interview questions set 6

Node.js: create an excel file with multiple tabs.