Statistics

Problem Statement for "RectangleHunt"

Problem Statement

You are given a set of points, given as (x, y) coordinates in int[]s x and y.

Return the area of the largest rectangle that can be formed from four of the points. If no four points can form a rectangle, return -1.

Definition

Class:
RectangleHunt
Method:
largest
Parameters:
int[], int[]
Returns:
double
Method signature:
double largest(int[] x, int[] y)
(be sure your method is public)

Notes

  • Your return value must be within 1e-9 absolute or relative error to be considered correct.

Constraints

  • x will contain between 4 and 50 elements, inclsuive.
  • x and y will contain the same number of elements.
  • Each element of x will be between 0 and 1000, inclusive.
  • Each element of y will be between 0 and 1000, inclusive.
  • No two points specified by x and y will be the same.

Examples

  1. {0, 1, 0, 1}

    {0, 2, 2, 0}

    Returns: 2.0

    There is only a single rectangle, 2x1 in size.

  2. {0, 1, 0, 1}

    {0, 2, 2, 3}

    Returns: -1.0

    These four points don't form a rectangle.

  3. {0, 5, 6, 11}

    {5, 2, 15, 12}

    Returns: 68.0

    The rectangle isn't necessarily aligned along the x-y grid.

  4. {1, 2, 3, 4}

    {1, 2, 3, 4}

    Returns: -1.0

  5. {0, 50, 60, 110}

    {50, 20, 150, 120}

    Returns: 6800.0

  6. {121,201,469,138,406,65,660,228,375,959,98,454,851,464,4,4,108,737,247,757,352,224,49,756,655,375,695,681,287,670,399,32,832,803,266,747,128,739,4,231,4,746,287,940,279,940,201,362,259,379}

    {474,511,492,203,363,208,105,994,493,91,175,495,139,657,960,363,182,226,862,762,292,572,704,231,101,657,62,94,708,113,44,501,44,700,512,522,196,394,976,562,233,343,662,343,643,539,151,308,522,5}

    Returns: -1.0

  7. {42,266,52,290,560,704,58,253,283,883,262,506,871,498,208,640,375,396,823,557,921,828,557,34,74,848,843,605,253,458,560,762,640,669,560,397,256,681,804,921,267,361,211,269,273,818,652,871,28,828}

    {760,287,738,819,561,43,742,878,813,602,795,670,324,436,466,576,127,71,459,887,561,467,324,726,817,499,491,410,597,576,879,93,505,706,505,173,996,965,38,505,38,392,829,801,35,885,981,887,722,336}

    Returns: 176782.0

  8. {684,913,494,596,497,480,555,133,663,629,589,172,497,152,663,662,537,89,651,227,670,945,396,960,667,341,745,283,152,821,320,586,723,677,523,194,283,647,221,283,430,716,933,454,219,619,586,667,874,511}

    {324,249,473,790,497,214,612,775,511,829,805,154,518,382,909,902,169,772,532,75,460,234,407,322,937,839,830,518,497,104,213,223,281,385,362,256,497,539,938,21,831,274,165,707,572,823,123,504,722,115}

    Returns: 4494.0

  9. {987,500,643,855,786,848,207,27,975,786,265,562,954,760,849,363,394,452,797,773,983,86,443,619,138,337,813,478,323,473,479,984,175,777,342,479,785,781,873,988,670,465,224,531,26,983,314,978,276,597}

    {350,427,291,31,539,610,795,275,382,448,959,431,289,409,562,415,505,306,788,537,174,773,948,175,675,549,542,502,69,353,539,358,432,538,722,448,540,539,790,5,584,174,814,682,951,277,3,374,236,10}

    Returns: 27937.0

  10. {253,386,978,753,853,831,925,355,457,385,30,267,235,196,442,443,826,831,995,104,931,390,119,978,321,291,457,270,389,841,77,308,535,108,766,325,542,389,875,865,847,920,387,959,37,878,871,115,889,846}

    {531,843,274,751,979,646,597,320,646,846,198,612,109,240,678,416,27,23,341,193,197,831,631,938,71,106,142,55,23,15,512,174,89,618,214,106,653,834,237,47,23,370,337,480,775,971,55,418,149,11}

    Returns: -1.0

  11. {880,933,233,831,863,0,864,268,0,792,711,162,803,788,859,781,120,743,945,706,935,822,933,262,897,925,963,555,594,711,933,62,430,148,942,514,824,993,776,591,404,935,906,778,935,91,603,923,906,968}

    {756,513,720,921,211,529,898,752,610,502,598,363,667,931,531,740,489,685,569,998,598,398,563,366,547,563,878,281,569,566,900,331,260,374,567,546,794,178,765,60,421,566,551,242,563,669,140,563,491,512}

    Returns: 7168.0

  12. {755,903,496,941,136,682,948,340,721,737,762,701,704,293,613,246,428,617,912,540,957,366,264,506,428,446,708,605,941,215,363,939,533,375,568,939,571,509,711,939,87,234,939,848,250,341,995,27,546,598}

    {642,209,59,443,779,803,184,278,110,956,76,845,593,800,824,555,855,282,204,391,179,130,704,65,804,804,983,679,602,735,649,607,126,92,57,589,346,563,570,595,227,809,601,445,938,447,805,798,89,137}

    Returns: -1.0

  13. {864,607,265,604,200,839,416,548,556,855,474,483,741,471,911,382,747,848,369,151,548,888,553,191,644,525,693,455,308,544,587,839,534,186,617,167,915,539,552,970,659,513,381,917,259,400,632,864,535,124}

    {928,507,57,278,917,933,850,498,66,86,439,523,850,130,907,610,715,709,968,280,979,659,341,33,546,458,175,565,220,480,473,928,229,702,516,588,574,496,825,400,437,770,925,571,282,149,737,933,478,324}

    Returns: 125.0

  14. {168,694,397,532,884,113,108,840,452,554,550,222,581,146,985,877,777,588,566,78,987,293,581,824,230,517,759,79,255,570,503,278,299,419,503,331,658,2,229,109,718,957,982,529,16,480,99,112,286,386}

    {477,151,650,262,176,565,610,897,310,107,522,9,542,186,421,288,862,735,481,613,754,685,826,440,250,549,561,623,685,855,346,463,965,720,105,972,939,987,538,620,706,734,759,215,943,881,609,758,831,617}

    Returns: 303.0

  15. {411,560,949,860,245,398,416,614,832,359,412,940,763,97,314,154,949,203,377,470,30,313,18,446,522,558,199,726,547,863,963,512,958,736,145,392,345,407,344,507,142,139,811,73,455,854,637,523,481,201}

    {185,625,116,827,700,151,182,769,815,438,186,125,624,662,368,286,134,400,500,486,994,159,566,466,28,729,533,546,34,827,198,877,125,630,214,332,873,716,998,196,280,286,13,883,657,342,643,832,437,894}

    Returns: 162.0

  16. {273,489,252,702,575,907,614,748,831,584,747,445,303,972,192,254,257,977,542,586,682,551,295,914,288,228,527,305,757,57,723,157,982,539,390,481,63,948,205,158,902,706,545,889,518,756,891,809,820,268}

    {822,360,838,349,235,796,367,754,650,630,757,454,816,995,773,371,842,642,783,532,977,775,755,299,18,577,748,97,757,234,708,802,536,772,719,884,52,770,671,549,673,173,677,942,756,760,352,975,749,818}

    Returns: 435.0

  17. {487,511,686,712,974,456,399,761,136,560,458,0,479,382,759,837,488,618,398,852,496,394,551,477,572,865,58,190,235,954,611,484,113,390,716,560,785,361,465,551,441,448,445,434,922,438,809,741,703,473}

    {138,807,993,243,950,879,333,764,636,673,574,988,135,19,973,492,111,906,762,352,114,586,700,175,287,347,140,22,524,767,692,0,965,288,856,700,848,270,584,673,207,471,598,347,595,588,84,110,393,472}

    Returns: 298.0

  18. {42,120,491,700,352,787,79,252,732,329,223,1,362,705,337,690,850,748,339,431,864,334,56,893,73,512,276,307,365,337,38,342,700,91,134,408,118,692,39,697,9,686,354,223,633,355,192,886,335,473}

    {367,186,567,106,360,942,883,748,550,598,568,753,357,959,867,500,941,822,530,924,104,602,881,397,657,464,697,474,367,588,941,592,955,138,430,201,694,965,651,969,130,681,226,152,274,370,843,923,144,769}

    Returns: 109.0

  19. {0, 5, 6, 11 }

    {5, 2, 15, 12 }

    Returns: 68.0

  20. {1000, 0, 1, 0, 1 }

    {1000, 0, 0, 1, 1 }

    Returns: 1.0

  21. {0, 1, 1, 2 }

    {0, 0, 1, 1 }

    Returns: -1.0

  22. {0, 1, 2, 3, 4, 4, 3 }

    {0, 0, 0, 0, 0, 1, 1 }

    Returns: 1.0

  23. {0, 1, 0, 1 }

    {0, 2, 2, 3 }

    Returns: -1.0

  24. {0, 3, 3, 6 }

    {2, 4, 0, 2 }

    Returns: -1.0

  25. {0, 0, 1000, 1000 }

    {0, 1000, 1000, 0 }

    Returns: 1000000.0

  26. {10, 5, 15, 10 }

    {5, 6, 6, 7 }

    Returns: -1.0

  27. {0, 1, 2, 3 }

    {0, 0, 1, 1 }

    Returns: -1.0

  28. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    Returns: -1.0

  29. {0, 1, 2, 1 }

    {0, 1, 1, 0 }

    Returns: -1.0

  30. {0, 1, 2, 3 }

    {0, 2, 1, 3 }

    Returns: -1.0

  31. {0, 0, 1, 1 }

    {0, 1, 0, 1 }

    Returns: 1.0

  32. {1, 4, 5, 6 }

    {1, 1, 1, 1 }

    Returns: -1.0

  33. {1, 3, 2, 0 }

    {0, 2, 1, 3 }

    Returns: -1.0

  34. {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6 }

    {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1 }

    Returns: 35.0

  35. {4, 7, 3, 0 }

    {4, 8, 11, 7 }

    Returns: 25.0

  36. {2, 2, 3, 0, 12, 11, 0, 1, 7, 8, 6, 7, 3, 0, 12, 14, 12, 7, 6, 5, 1, 4, 4, 2, 3, 0, 14, 0, 0, 0, 4, 5, 15, 7, 13, 15, 15, 6, 2, 5, 15, 9, 2, 8, 9, 4, 7, 10, 8, 14 }

    {11, 2, 12, 2, 3, 15, 14, 4, 15, 6, 10, 2, 0, 15, 15, 5, 6, 4, 3, 14, 9, 2, 13, 4, 3, 7, 8, 4, 10, 0, 6, 7, 12, 12, 15, 11, 2, 11, 3, 5, 3, 9, 10, 12, 10, 0, 10, 2, 10, 7 }

    Returns: 117.0

  37. {0, 1, 2, 3 }

    {0, 2, 0, 2 }

    Returns: -1.0

  38. {0, 1, 2, 3 }

    {0, 1, 0, 1 }

    Returns: -1.0

  39. {0, 2, 7, 5 }

    {0, 2, 2, 0 }

    Returns: -1.0


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: