You are not logged in. Please login at to post your questions!


WA in Cook Off 54 : Abhijeet and rectangles

I understood the editorial to the question but why does my approach not work?

My approach-

Sort the lengths and breadth in two different lists and maintain pointers to the first element of each of them. Let's call these two lists l and b, and the two pointers i and j for our convenience.

Let A1 = l[i] * b[j+1] and A2 = l[i+1] * b[j]

(i.e. A1 = smallest length * second smallest breadth; A2 = second smallest length * smallest breadth)

If A1 < A2 remove the rectangle with shortest length and mark it as removed else remove rectangle with shortest breadth and mark that as removed. My code

Any help will be appreciated!

asked 23 Jan '15, 00:55

vastolorde95's gravatar image

5★vastolorde95 ♦
accept rate: 11%

edited 23 Jan '15, 00:59

What answer are you getting for this case... Ans should be 10!!

3 2
2 3
3 3
1 10

answered 23 Jan '15, 07:27

kunal361's gravatar image

accept rate: 21%

I am getting 9, the code removes the wrong rectangle. Got my mistake! Thanks!

(24 Jan '15, 01:45) vastolorde95 ♦5★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 23 Jan '15, 00:55

question was seen: 1,903 times

last updated: 24 Jan '15, 01:45