Compute the area covered by cards randomly put on a table

前端 未结 5 1339
故里飘歌
故里飘歌 2021-02-07 10:20

This is an interview question, the interview has been done.

Given a deck of rectangular cards, put them randomly on a rectangular table whose size is much larger than t

5条回答
  •  失恋的感觉
    2021-02-07 10:48

    T = The total area of the table.

    C = The total area that could be covered by cards (area of one card times number of cards).

    V = The total area of overlapping cards (V = oVerlap)

    Area to calculate = T - (C - V)

    There should be (yep, those are danger words) some way to efficiently analyze the space occupied by the cards, to readily identify overlapping vs. non-overlapping situations. Identify these, factor out all overlapped areas, and you're done.

    Time complexity would be in considering each card in order, one by one, and comparing each with each remaining card (card 2 has already been checked against card 1), which makes it n!, not good... but this is where the "should" comes in. There must be some efficient way to remove all cards that do not overlap from consideration, to order cards to make it obvious if they could not possibly overlap other/prior cards, and perhaps to identify or group potentially overlapping cards.

    Interesting problem.

提交回复
热议问题