Problem Statement
You work in a workshop which makes garden instruments from metal. At the end of each working day there remains a pile of scrap metal that cannot be used to make anything useful. Because you dislike the idea of throwing things away (even scrap metal), you decide to utilize this metal to make some triangular picture frames that can be sold at the local market.
Given a
Definition
- Class:
- Workshop
- Method:
- pictureFrames
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int pictureFrames(int[] pieces)
- (be sure your method is public)
Notes
- A triangle can be formed if, and only if, for every pair of its sides the sum of that pair is longer than the third side.
Constraints
- pieces will have between 0 and 50 elements inclusive.
- Each element in pieces will be between 1 and 10000 inclusive.
- pieces will not have any repeated elements.
Examples
{1,2,3,4,5}
Returns: 3
We can form picture frames with the following sides: {2, 3, 4}, {2, 4, 5} and {3, 4, 5}. So we can form 3 different picture frames.
{8,5,3}
Returns: 0
8 + 5 is longer than 3 and 8 + 3 is longer than 5, but 5 + 3 is not longer than 8. Thus we cannot form a single picture frame from these pieces.
{4,23,76,22,87,3,1,99}
Returns: 7
{10000,9999,9998,9997,9996,1,2,3,4,5}
Returns: 43
{100}
Returns: 0
We cannot form any picture frames with just one piece of metal.
{6419,4679,6975,9285,6727,7377,48,2476,1868,2185,7270,2600,6577,4553,5133,5241,3772,2166,5536,3395,857,2457,707,6587,9730,9817,7976,4295,5475,3273,2632,1970,6619,9913,8964,2643,8024,6712,6639,9624,6059,3562,2068}
Returns: 6779
{4475,3294,2105,5666,8603,280,504,3477,4935,7795,5924,2043,2934,5727,3952,6553,5993,4485,4612,4548,8881,7954,1129,1719,9713,8234,5336,632,5514,7533,54}
Returns: 2173
{1789,8107,9008,9238,8133,9385,398,3615,3930,2540}
Returns: 59
{7382,417,6701,4855,1552}
Returns: 2
{7693,8530,713,546,9767,8921,5045,1876,3104,2683,7771,2564,5077,1027,1513,9832,1211,2745,174,6784,2562,7415,3902,2040,9881,3997,3462,5516,1298,8677,6906,1163,9517,9844,5821,2923,6551,7379,627,5834}
Returns: 3890
{8037,4416,269,3489,8678,2635,3620,6106,4288,1555,374,5438,8347,1920,8530,4353,8931,5418,7541,7012,5119,705,573,3137,4806,2576,1771,4985,6769,2598,7433,9996,7018,2016,8524,2243,1845,8055,782,8761,7746,2914,7846,2683,1467}
Returns: 6467
{2276,3644,1753}
Returns: 1
{9122,7392,8100,43}
Returns: 1
{729,777,9862,274,4973,717,367,2841,971,7454,9550,2660,1364,8276,4600,2981,1293,1941,325,5497,6997,5913,8818,8808,2900,6909,660,6069,1658,763,2045,8523,8396,9058}
Returns: 1727
{4524,9890,6844,266,6833,1811,7830,5494,4550,2300,892,5572,9828,8148,4480,8986,3707,612,3572,3905}
Returns: 528
{1535,7161,2014,9717,6824,2991,7389,7890,3597,203,3013,1496,9320,9902,9708,3588,6145,8235,2283,6211,1286,6538,5531,5298,4783,8324,8313,6166,9279,3468,7437,5350,2532,5786,4305,1791,2316,1412,6333,7975,5083,1849,2105,9527,4307,7406,3831,9973,1767,3809}
Returns: 10729
{5908,5216,7251,7567,6648,8849,863,9522,1604,8768,8642,2941,8046,4256,1273,7243}
Returns: 348
{7088,1910,7243,3048,5326,9034,3356,1297}
Returns: 22
{7771,4650,1343,3687,689,2206,6756,12,4017,3075,5830,3871,5488,5723,8019,3858,5542,6334,483,4757,4521,1591,6638,9248,4637}
Returns: 1234
{1223,5450,7019,6637,9305,1372,947,2709,9822,9696,4460,5169,7829,1494,3029,4032,3407,5431,5663,4503,9404,9834,5903,8824,4565,8577,8536,2379,3454,8170,1518,7594,9619,2664,6615,3524,3846,5017}
Returns: 4927
{1230,5104,8415,1096,5062,7754,8747}
Returns: 18
{7770,4974,9849,1499,3016,4979,6480,1134,2309,3592,6056,625,4616,3989,9115,6266,6021,2031,194,1997,3645,3494}
Returns: 676
{4504,2764,7734,9855,416,8557,824,9990,3668,4254,67,5364,8821,5572,916,4572,9204,7279,6807,5141,7100,1502,2185,355,6888,8933,9094}
Returns: 1286
{1036,3513,8078,6836,3169,8340,4908,8475,2023,5561,5596,949,5062,5856,3585,5815,745,3720,4570,4873,4023,3217,6429,5692,470,5143,3990,2786,698,602,947,6274,8114,7864,4162,9412,9977,9117,8758,8737,3754,1182,5996,5721,8256,9632,9702,6827,1752}
Returns: 9827
{1206,9630,7330,1495,7202,6286,9140,9764,9708,2050,1822,7060,2404,5741,9448,3497,3018,1147,9570,533,7146,3161,2631,188,4923,148,6884,2093,8284,4488,4253,7241,3228,6562,3079,780,8429,3527,9606,7420,8859,3153,1213,2121,615}
Returns: 5747
{915,5610,1113,3527,4434,8958,6954,2885,8302,3974,351,7681,9845,6485,3808,6530,7668,7719,1907,5360,4318,4932,8518,3850}
Returns: 1176
{6208,7523,7585,9158,5905}
Returns: 10
{2994,8370,6638,3082,9195,3028,842,9875,719,8993,21,3935,7753,5064,2565,6772,6016,9995,1678,1611,6677,2581,3403,2020,7829,3067}
Returns: 1059
{8204,2940,288,5871,1085}
Returns: 1
{473,7593,7207,2191,428,4365,704,6703,9954,3862,2111,6648,5756,8870,7618,7517,1884,5699,6533,3627,9767,4140,9172,6985,4298,6572,2174,5034,1087,333,3329,4512,4005,1899,3397,696,1455,3589,8130,6164,4405,3541,9704}
Returns: 5833
{}
Returns: 0
{10000}
Returns: 0
{10000,9999}
Returns: 0
{10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,9988,9987,9986,9985,9984,9983,9982,9981,9980,9979,9978,9977,9976,9975,9974,9973,9972,9971,9970,9969,9968,9967,9966,9965,9964,9963,9962,9961,9960,9959,9958,9957,9956,9955,9954,9953,9952,9951}
Returns: 19600
{ 10000, 9999, 9998, 9997, 9996, 1, 2, 3, 4, 5 }
Returns: 43
{ 2, 3, 4 }
Returns: 1
{ 4, 23, 76, 22, 87, 3, 1, 99, 46, 34, 63, 323, 888, 975, 754, 543 }
Returns: 39
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 }
Returns: 9500
{ 1, 2, 3, 4, 5 }
Returns: 3
{ 4, 23, 76, 22, 87, 3, 1, 99 }
Returns: 7