Statistics

Problem Statement for "Skyscrapers"

Problem Statement

The skyline of the city of Terrapin City has N buildings all in a straight line; each building has a distinct height between 1 and N, inclusive. The building at index i is considered visible from the left is there is no building with a smaller index that is taller (formally, height[j] &lt height[i] for all j &lt i). Similarly, a building is visible from the right if there is no taller building with a higher index (height[j] &lt height[i] for all j &gt i). For example, if the buildings in order are {1, 3, 5, 2, 4}, then three buildings are visible from the left (1, 3 and 5), but only two are visible from the right (4 and 5).

You will be given N, leftSide and rightSide, corresponding to the total number of buildings, the buildings visible from the left, and the buildings visible from the right, respectively. Return the number of permutations of the buildings that are consistent with these values; as this can be a large number, you should return it modulo 1000000007.

Definition

Class:
Skyscrapers
Method:
buildingCount
Parameters:
int, int, int
Returns:
int
Method signature:
int buildingCount(int N, int leftSide, int rightSide)
(be sure your method is public)

Constraints

  • N will be between 1 and 100, inclusive.
  • leftSide and rightSide will be between 1 and N, inclusive.

Examples

  1. 3

    2

    2

    Returns: 2

    There are two arrangements of buildings that match these requirements: {1, 3, 2} and {2, 3, 1}.

  2. 3

    2

    1

    Returns: 1

    Only {2, 1, 3} fits these requirements.

  3. 5

    3

    2

    Returns: 18

  4. 100

    2

    1

    Returns: 990953332

  5. 100

    13

    21

    Returns: 492729563

  6. 12

    1

    1

    Returns: 0

    With 12 buildings, it is impossible for you to only see one building from each side.

  7. 8

    3

    2

    Returns: 4872

  8. 15

    2

    1

    Returns: 227020758

  9. 14

    2

    1

    Returns: 479001600

  10. 12

    11

    3

    Returns: 0

  11. 78

    44

    56

    Returns: 0

  12. 87

    23

    11

    Returns: 699722100

  13. 100

    99

    99

    Returns: 0

  14. 100

    95

    4

    Returns: 310413463

  15. 100

    49

    52

    Returns: 504025591

  16. 67

    32

    24

    Returns: 905017808

  17. 7

    6

    2

    Returns: 6

  18. 9

    5

    5

    Returns: 70

  19. 24

    18

    9

    Returns: 0

  20. 1

    1

    1

    Returns: 1

    Minimum N.

  21. 2

    2

    1

    Returns: 1

  22. 72

    1

    72

    Returns: 1

  23. 87

    87

    1

    Returns: 1

  24. 16

    16

    1

    Returns: 1

  25. 37

    1

    37

    Returns: 1

  26. 29

    12

    15

    Returns: 269928514

  27. 77

    6

    10

    Returns: 999993982

    Maximal return value

  28. 73

    11

    2

    Returns: 999991807

  29. 80

    30

    50

    Returns: 999983834

  30. 95

    40

    54

    Returns: 999954301

  31. 66

    5

    5

    Returns: 999953844

  32. 100

    8

    7

    Returns: 610390291

  33. 58

    32

    44

    Returns: 0

  34. 87

    5

    13

    Returns: 540283095

  35. 86

    12

    34

    Returns: 810933864

  36. 78

    54

    22

    Returns: 185138699

  37. 90

    45

    47

    Returns: 0

  38. 90

    45

    46

    Returns: 722170429

  39. 38

    1

    1

    Returns: 0

  40. 87

    1

    1

    Returns: 0

  41. 44

    34

    8

    Returns: 956315439

  42. 71

    55

    8

    Returns: 329451734

  43. 94

    94

    1

    Returns: 1

  44. 87

    1

    87

    Returns: 1

  45. 36

    13

    24

    Returns: 834451800

  46. 12

    3

    1

    Returns: 10628640

  47. 14

    1

    1

    Returns: 0

  48. 9

    9

    2

    Returns: 0

  49. 100

    24

    24

    Returns: 520063872

  50. 100

    40

    41

    Returns: 911646200

  51. 98

    17

    42

    Returns: 393135880

  52. 100

    20

    23

    Returns: 959802400

  53. 99

    50

    49

    Returns: 528934656

  54. 100

    25

    25

    Returns: 848175703

  55. 100

    32

    21

    Returns: 790323138

  56. 100

    100

    1

    Returns: 1

  57. 100

    20

    40

    Returns: 667870492

  58. 100

    2

    2

    Returns: 598881956

  59. 100

    23

    37

    Returns: 714070384

  60. 100

    39

    29

    Returns: 550026577

  61. 100

    25

    37

    Returns: 702363931

  62. 100

    25

    61

    Returns: 928920281

  63. 100

    50

    50

    Returns: 265248055

  64. 100

    53

    37

    Returns: 403760718

  65. 100

    7

    8

    Returns: 610390291

  66. 100

    35

    35

    Returns: 151954186

  67. 100

    20

    20

    Returns: 986752476

  68. 100

    49

    50

    Returns: 658420915

  69. 100

    49

    30

    Returns: 175486704

  70. 100

    20

    29

    Returns: 929804441

  71. 21

    8

    5

    Returns: 651222009

  72. 100

    50

    51

    Returns: 769496025

  73. 23

    9

    6

    Returns: 384590516

  74. 99

    7

    7

    Returns: 56353603

  75. 100

    10

    10

    Returns: 559891373


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: