code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

492 Construct The Rectangle

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

function constructTheRectangle(area) {
  let width = Math.floor(Math.sqrt(area))
  while(width > 0){
    let length = area/width
    if(Number.isInteger(length)){
      return [length, width]
    }
    width--
  }
}

test('construct The Rectangle', () => {
  expect(constructTheRectangle(4)).toEqual([2,2])
});

Created 2020-04-18T20:26:17+00:00 · Edit