Search Insert Position

Easy

You are given an array of distinct integers nums sorted in ascending order, and an integer target.

If target is in nums, return its index. If it isn't, return the index where it would be if it were inserted in order, so that nums stays sorted.

You must write an algorithm with O(log n) runtime complexity.

Examples

Example 1

Input:  nums = [1,3,5,6], target = 5
Output: 2

5 is in the array, at index 2.

Example 2

Input:  nums = [1,3,5,6], target = 2
Output: 1

2 isn't in the array. It belongs between 1 and 3, so it would be inserted at index 1: [1,2,3,5,6].

Example 3

Input:  nums = [1,3,5,6], target = 7
Output: 4

7 is larger than every element, so it goes at the very end: index 4, one past the last element.

Example 4

Input:  nums = [1,3,5,6], target = 0
Output: 0

0 is smaller than every element, so it goes at the front.

Example 5

Input:  nums = [-10,-3,0,5,9], target = -4
Output: 1

−4 sits between −10 and −3: [-10,-4,-3,0,5,9].

Constraints

  • 1 <= nums.length <= 10^4
  • -10^4 <= nums[i] <= 10^4
  • nums contains distinct values sorted in ascending order
  • -10^4 <= target <= 10^4
TypeScript
Loading editor…
Test cases35
Case 1
nums = [1,3,5,6]
target = 5
Case 2
nums = [1,3,5,6]
target = 2
Case 3
nums = [1,3,5,6]
target = 7
Case 4
nums = [1,3,5,6]
target = 0
Case 5
nums = [-10,-3,0,5,9]
target = -4
Case 6
nums = [1]
target = 0
Case 7
nums = [1]
target = 1
Case 8
nums = [1]
target = 2
Case 9
nums = [1,3]
target = 0
Case 10
nums = [1,3]
target = 1
Case 11
nums = [1,3]
target = 2
Case 12
nums = [1,3]
target = 3
Case 13
nums = [1,3]
target = 4
Case 14
nums = [1,3,5,7,9,11]
target = 6
Case 15
nums = [1,3,5,7,9,11]
target = 12
Case 16
nums = [1,3,5,7,9,11]
target = 11
Case 17
nums = [-10,-3,0,5,9]
target = -10
Case 18
nums = [-10,-3,0,5,9]
target = -11
Case 19
nums = [-10,-3,0,5,9]
target = 9
Case 20
nums = [-10,-3,0,5,9]
target = 10
Case 21
nums = [-10,-3,0,5,9]
target = 1
Case 22
nums = [-10000,10000]
target = -10000
Case 23
nums = [-10000,10000]
target = 0
Case 24
nums = [-10000,10000]
target = 10000
Case 25
nums = [2,4,6,8,10,12,14,16]
target = 9
Case 26
nums = [2,4,6,8,10,12,14,16]
target = 15
Case 27
nums = [2,4,6,8,10,12,14,16]
target = 3
Case 28
nums = [0,1,2,3,4,5,6]
target = 3
Case 29
nums = [-8951,-8723,-8490,-8384,-8346,-7957,-7854,-7318,-7042,-7031,-6960,-6950,-6269,-5460,-5150,-4963,-4816,-4431,-3329,-3305,-3241,-3220,-3033,-2999,-2934,-2712,-1934,-1172,-987,210,280,458,509,569,3336,3993,4570,5003,5064,5254,5773,6226,6584,6657,7288,8237,8640,9025,9116,9810]
target = -6269
Case 30
nums = [-9911,-9785,-9645,-9516,-9482,-9415,-9389,-9307,-9278,-9224,-9063,-9012,-8816,-8802,-8786,-8522,-8374,-8308,-8253,-8162,-8073,-8014,-7945,-7943,-7937,-7910,-7908,-7746,-7601,-7485,-7439,-7426,-7400,-7274,-7247,-7060,-7018,-6991,-6878,-6846,-6814,-6714,-6605,-6570,-6546,-6517,-6386,-6363,-6207,-6201,-6166,-6052,-6051,-6030,-5978,-5965,-5894,-5754,-5723,-5720,-5707,-5613,-5593,-5426,-5315,-5248,-5101,-4855,-4832,-4781,-4774,-4757,-4748,-4693,-4539,-4441,-4403,-4367,-4342,-4297,-4269,-4245,-4159,-4105,-4078,-4075,-4028,-4026,-3965,-3810,-3788,-3744,-3704,-3651,-3567,-3338,-3334,-3228,-3140,-2913,-2905,-2862,-2813,-2675,-2623,-2566,-2562,-2266,-2183,-1966,-1965,-1933,-1705,-1632,-1556,-1538,-1511,-1260,-1223,-1009,-992,-841,-776,-702,-678,-568,-558,-470,-465,-408,-321,-307,-229,-194,-91,-76,-40,-20,13,158,163,190,201,283,385,587,659,885,914,970,1046,1087,1121,1185,1274,1297,1316,1378,1388,1490,1499,1556,1562,1636,1689,1690,1709,1735,1778,1813,1934,1978,2090,2138,2204,2222,2354,2371,2410,2419,2450,2502,2541,2715,2732,2788,2853,2890,2895,2914,2960,2993,3008,3019,3058,3101,3170,3172,3176,3494,3599,3698,3800,3818,3821,3891,4070,4078,4104,4105,4243,4293,4356,4387,4477,4544,4562,4563,4570,4583,4699,4771,4858,4862,4887,4946,5063,5108,5201,5258,5292,5373,5426,5539,5563,5594,5633,5711,5862,5906,5924,6028,6048,6099,6142,6180,6189,6314,6403,6476,6522,6528,6636,6780,6843,6850,6890,6891,6910,6921,6963,6967,7031,7041,7073,7100,7118,7199,7202,7286,7682,7699,7745,7749,7855,7911,8007,8026,8044,8072,8257,8367,8601,8686,8694,8781,8953,8963,9019,9086,9196,9266,9357,9488,9550,9604,9710,9798,9877,9959]
target = -4072
Case 31
nums = [-9983,-9975,-9957,-9937,-9928,-9927,-9918,-9898,-9877,-9871,-9858,-9815,-9787,-9768,-9752,-9749,-9748,-9681,-9657,-9654,-9649,-9647,-9635,-9628,-9623,-9611,-9603,-9597,-9595,-9585,-9562,-9524,-9520,-9473,-9471,-9470,-9466,-9458,-9448,-9421,-9412,-9385,-9384,-9354,-9337,-9332,-9326,-9260,-9245,-9236,-9233,-9227,-9217,-9200,-9189,-9175,-9158,-9153,-9149,-9145,-9144,-9130,-9091,-9072,-9006,-8987,-8926,-8914,-8890,-8878,-8876,-8838,-8828,-8827,-8795,-8785,-8777,-8759,-8746,-8718,-8712,-8672,-8656,-8636,-8633,-8627,-8618,-8615,-8604,-8598,-8591,-8577,-8564,-8542,-8529,-8526,-8514,-8493,-8486,-8458,-8438,-8418,-8406,-8390,-8376,-8358,-8344,-8341,-8339,-8335,-8326,-8279,-8249,-8231,-8218,-8208,-8157,-8155,-8092,-8087,-8085,-8081,-8034,-7993,-7982,-7959,-7880,-7869,-7863,-7855,-7821,-7781,-7757,-7720,-7717,-7662,-7649,-7586,-7582,-7577,-7566,-7564,-7562,-7557,-7555,-7552,-7505,-7488,-7483,-7456,-7430,-7426,-7415,-7401,-7382,-7376,-7363,-7344,-7286,-7267,-7264,-7233,-7222,-7182,-7159,-7153,-7149,-7131,-7102,-7064,-7058,-7038,-7022,-7000,-6988,-6948,-6911,-6905,-6904,-6883,-6875,-6823,-6808,-6787,-6744,-6734,-6728,-6724,-6718,-6707,-6693,-6680,-6664,-6645,-6643,-6613,-6612,-6545,-6536,-6525,-6521,-6499,-6487,-6452,-6429,-6387,-6383,-6335,-6318,-6304,-6300,-6299,-6282,-6276,-6264,-6245,-6226,-6191,-6171,-6163,-6138,-6121,-6110,-6100,-6081,-6078,-6058,-6038,-6011,-6005,-6004,-5953,-5918,-5784,-5783,-5781,-5757,-5748,-5747,-5683,-5626,-5616,-5605,-5576,-5552,-5543,-5527,-5444,-5431,-5416,-5387,-5373,-5370,-5363,-5349,-5344,-5329,-5319,-5298,-5296,-5279,-5246,-5245,-5212,-5209,-5169,-5137,-5063,-5059,-5012,-4939,-4928,-4893,-4865,-4825,-4804,-4800,-4794,-4792,-4778,-4766,-4750,-4746,-4697,-4679,-4635,-4563,-4535,-4497,-4476,-4457,-4406,-4380,-4366,-4336,-4326,-4325,-4277,-4276,-4274,-4269,-4267,-4266,-4265,-4247,-4212,-4196,-4151,-4098,-4050,-4041,-4011,-4010,-4002,-3999,-3987,-3947,-3934,-3924,-3884,-3867,-3858,-3857,-3848,-3822,-3784,-3781,-3755,-3744,-3742,-3733,-3726,-3709,-3703,-3697,-3663,-3651,-3635,-3616,-3582,-3550,-3544,-3541,-3531,-3498,-3480,-3454,-3434,-3368,-3356,-3321,-3303,-3291,-3288,-3262,-3260,-3220,-3193,-3160,-3127,-3121,-3098,-3054,-3048,-3036,-3009,-2944,-2934,-2928,-2913,-2910,-2893,-2884,-2797,-2752,-2750,-2736,-2731,-2699,-2698,-2656,-2617,-2581,-2526,-2482,-2459,-2458,-2380,-2366,-2353,-2348,-2342,-2340,-2321,-2292,-2287,-2245,-2195,-2186,-2185,-2160,-2143,-2117,-2114,-2102,-2098,-2081,-2031,-1999,-1991,-1971,-1966,-1943,-1900,-1888,-1795,-1794,-1782,-1753,-1738,-1726,-1717,-1696,-1677,-1670,-1648,-1596,-1575,-1554,-1511,-1510,-1509,-1460,-1429,-1413,-1412,-1393,-1367,-1356,-1313,-1303,-1295,-1293,-1277,-1255,-1240,-1229,-1223,-1169,-1045,-1031,-1017,-991,-930,-922,-919,-909,-869,-823,-820,-802,-758,-755,-729,-722,-721,-718,-696,-691,-690,-666,-658,-652,-644,-618,-509,-481,-468,-466,-452,-425,-414,-408,-351,-335,-311,-301,-282,-216,-173,-147,-124,-112,-37,-6,1,16,56,62,67,80,85,110,111,117,122,124,128,131,145,157,176,195,205,226,245,318,324,330,364,375,376,391,397,412,420,446,511,525,534,555,570,593,594,633,637,687,705,718,750,751,774,789,791,821,838,869,890,917,933,968,984,1001,1024,1044,1054,1056,1060,1085,1088,1124,1158,1191,1211,1265,1307,1312,1319,1343,1345,1378,1401,1403,1472,1498,1522,1569,1580,1604,1606,1634,1635,1669,1673,1684,1695,1719,1733,1750,1798,1844,1858,1875,1880,1900,1908,1921,1925,1944,1963,1965,2007,2010,2050,2083,2084,2086,2109,2213,2228,2248,2300,2305,2312,2330,2344,2351,2445,2493,2494,2510,2516,2524,2530,2537,2581,2595,2604,2605,2614,2630,2652,2680,2693,2703,2742,2746,2759,2771,2779,2786,2804,2823,2829,2849,2868,2899,2906,2907,2954,2964,3013,3022,3044,3068,3097,3121,3129,3131,3184,3234,3238,3252,3261,3273,3320,3330,3333,3354,3369,3393,3411,3435,3444,3481,3513,3521,3541,3576,3588,3596,3599,3600,3613,3614,3681,3686,3690,3743,3749,3775,3791,3804,3827,3837,3871,3877,3888,3890,3925,3937,3938,3947,3973,3982,4020,4022,4072,4106,4111,4123,4128,4148,4188,4219,4231,4252,4261,4263,4285,4302,4337,4360,4369,4374,4377,4378,4449,4450,4462,4532,4543,4565,4588,4619,4626,4661,4702,4709,4720,4727,4751,4810,4811,4816,4837,4844,4903,4910,4925,4934,4961,4994,5010,5021,5051,5090,5143,5146,5184,5186,5193,5201,5212,5253,5258,5268,5304,5316,5336,5349,5405,5420,5429,5439,5464,5466,5501,5502,5516,5545,5573,5665,5669,5672,5707,5708,5738,5764,5872,5912,5944,6000,6018,6027,6031,6071,6081,6085,6092,6117,6121,6125,6153,6164,6171,6183,6190,6204,6292,6300,6332,6338,6390,6402,6416,6417,6420,6422,6430,6464,6487,6488,6506,6508,6558,6571,6620,6626,6638,6658,6688,6750,6770,6773,6777,6848,6868,6869,6884,6893,6894,6904,6908,6940,6944,6958,6972,7001,7013,7019,7021,7088,7101,7110,7140,7167,7189,7190,7204,7211,7216,7263,7333,7338,7342,7368,7382,7391,7426,7452,7454,7517,7523,7535,7557,7615,7621,7656,7665,7689,7691,7733,7734,7737,7771,7780,7806,7821,7839,7859,7867,7886,7911,7926,7969,7983,7997,8008,8010,8025,8047,8054,8056,8080,8097,8106,8109,8114,8150,8154,8168,8189,8190,8203,8254,8255,8282,8297,8302,8308,8326,8357,8361,8381,8385,8404,8417,8426,8444,8479,8519,8556,8590,8594,8637,8661,8663,8664,8668,8687,8719,8725,8782,8794,8803,8847,8875,8900,8910,8942,8944,8948,8989,9005,9017,9021,9090,9134,9137,9147,9205,9238,9247,9258,9268,9282,9316,9321,9332,9428,9453,9461,9478,9479,9483,9484,9502,9504,9510,9529,9545,9546,9584,9591,9607,9648,9665,9672,9684,9712,9811,9818,9834,9852,9855,9865,9913,9988,9997]
target = -9286
Case 32
nums = [-9995,-9988,-9981,-9980,-9975,-9948,-9944,-9937,-9932,-9907,-9876,-9875,-9862,-9817,-9808,-9789,-9775,-9774,-9758,-9737,-9729,-9723,-9715,-9701,-9687,-9677,-9670,-9651,-9648,-9638,-9633,-9620,-9598,-9575,-9568,-9567,-9565,-9559,-9540,-9528,-9500,-9499,-9489,-9478,-9477,-9453,-9386,-9367,-9359,-9356,-9345,-9304,-9303,-9302,-9290,-9288,-9283,-9281,-9244,-9238,-9234,-9215,-9213,-9191,-9180,-9179,-9173,-9166,-9155,-9098,-9090,-9053,-9017,-9010,-9000,-8999,-8984,-8964,-8953,-8943,-8914,-8911,-8851,-8836,-8824,-8795,-8786,-8764,-8741,-8738,-8733,-8732,-8727,-8725,-8696,-8675,-8633,-8615,-8593,-8589,-8580,-8579,-8576,-8556,-8520,-8514,-8495,-8483,-8478,-8452,-8450,-8430,-8408,-8401,-8388,-8365,-8364,-8359,-8348,-8341,-8309,-8303,-8299,-8297,-8294,-8292,-8288,-8285,-8283,-8276,-8268,-8242,-8241,-8238,-8224,-8208,-8206,-8186,-8174,-8173,-8152,-8131,-8122,-8097,-8060,-8051,-8032,-8021,-8019,-8015,-8003,-8000,-7992,-7982,-7981,-7973,-7962,-7961,-7943,-7901,-7882,-7878,-7833,-7814,-7778,-7765,-7762,-7759,-7751,-7744,-7737,-7733,-7713,-7710,-7703,-7694,-7684,-7649,-7643,-7638,-7622,-7619,-7617,-7581,-7572,-7563,-7538,-7533,-7532,-7521,-7516,-7514,-7513,-7506,-7489,-7486,-7480,-7473,-7466,-7452,-7411,-7404,-7384,-7357,-7352,-7344,-7336,-7330,-7251,-7239,-7237,-7205,-7172,-7154,-7153,-7116,-7091,-7087,-7076,-7052,-7047,-7018,-7000,-6994,-6984,-6960,-6955,-6945,-6936,-6923,-6919,-6896,-6883,-6875,-6866,-6860,-6853,-6851,-6839,-6812,-6743,-6734,-6716,-6703,-6700,-6691,-6681,-6675,-6666,-6643,-6564,-6537,-6524,-6523,-6518,-6515,-6514,-6504,-6500,-6477,-6469,-6468,-6437,-6436,-6429,-6426,-6411,-6408,-6401,-6381,-6370,-6361,-6360,-6338,-6314,-6302,-6298,-6297,-6249,-6243,-6220,-6219,-6216,-6215,-6197,-6195,-6187,-6183,-6174,-6170,-6169,-6158,-6157,-6154,-6141,-6124,-6123,-6086,-6080,-6046,-6029,-6021,-5980,-5955,-5941,-5932,-5929,-5923,-5917,-5903,-5897,-5893,-5860,-5854,-5852,-5851,-5844,-5822,-5797,-5796,-5792,-5778,-5772,-5756,-5754,-5729,-5709,-5702,-5699,-5692,-5682,-5670,-5669,-5667,-5664,-5661,-5660,-5626,-5616,-5605,-5604,-5581,-5573,-5547,-5531,-5527,-5523,-5520,-5514,-5512,-5494,-5491,-5483,-5467,-5443,-5441,-5413,-5407,-5404,-5385,-5382,-5377,-5373,-5353,-5340,-5320,-5316,-5308,-5306,-5287,-5261,-5256,-5252,-5249,-5236,-5230,-5228,-5223,-5222,-5220,-5185,-5182,-5177,-5172,-5151,-5150,-5133,-5116,-5090,-5084,-5062,-5021,-4996,-4985,-4948,-4931,-4925,-4919,-4907,-4903,-4896,-4892,-4877,-4865,-4864,-4828,-4817,-4813,-4798,-4756,-4744,-4732,-4728,-4723,-4720,-4715,-4689,-4666,-4648,-4642,-4637,-4608,-4588,-4583,-4571,-4567,-4562,-4537,-4531,-4487,-4472,-4452,-4439,-4415,-4410,-4404,-4378,-4376,-4355,-4350,-4339,-4316,-4312,-4308,-4287,-4271,-4261,-4259,-4252,-4246,-4227,-4221,-4220,-4214,-4211,-4208,-4201,-4161,-4143,-4113,-4111,-4102,-4096,-4073,-4046,-4044,-4042,-4040,-4017,-4016,-4009,-4008,-4004,-3986,-3985,-3984,-3961,-3956,-3949,-3940,-3924,-3916,-3909,-3901,-3887,-3883,-3864,-3862,-3823,-3817,-3815,-3793,-3790,-3781,-3760,-3756,-3754,-3752,-3732,-3725,-3723,-3675,-3655,-3647,-3631,-3623,-3613,-3604,-3601,-3577,-3572,-3571,-3550,-3506,-3504,-3498,-3497,-3441,-3433,-3426,-3425,-3419,-3418,-3399,-3343,-3339,-3329,-3318,-3309,-3305,-3270,-3262,-3213,-3169,-3153,-3146,-3137,-3123,-3096,-3095,-3091,-3073,-3071,-3054,-3052,-3043,-3041,-3022,-3018,-3016,-3008,-3000,-2959,-2954,-2942,-2934,-2920,-2919,-2915,-2903,-2868,-2841,-2784,-2780,-2771,-2761,-2758,-2755,-2712,-2679,-2665,-2655,-2653,-2649,-2647,-2642,-2641,-2638,-2617,-2614,-2613,-2611,-2608,-2600,-2599,-2596,-2588,-2580,-2579,-2574,-2561,-2536,-2534,-2515,-2514,-2462,-2458,-2450,-2420,-2413,-2401,-2394,-2384,-2382,-2348,-2346,-2343,-2326,-2282,-2248,-2243,-2240,-2203,-2201,-2177,-2176,-2170,-2134,-2125,-2103,-2062,-2045,-2041,-1978,-1956,-1954,-1945,-1941,-1927,-1907,-1896,-1891,-1889,-1882,-1871,-1870,-1836,-1817,-1806,-1801,-1784,-1783,-1765,-1740,-1739,-1729,-1719,-1714,-1704,-1700,-1653,-1650,-1648,-1642,-1628,-1625,-1587,-1566,-1537,-1536,-1535,-1499,-1491,-1466,-1438,-1430,-1424,-1401,-1398,-1356,-1348,-1321,-1320,-1318,-1309,-1292,-1285,-1274,-1269,-1264,-1263,-1230,-1211,-1204,-1193,-1179,-1174,-1170,-1163,-1147,-1123,-1098,-1089,-1073,-1048,-1026,-1014,-951,-939,-934,-889,-879,-872,-868,-867,-863,-853,-850,-818,-808,-803,-797,-796,-786,-780,-760,-750,-745,-742,-738,-728,-703,-697,-686,-663,-645,-642,-641,-623,-617,-612,-597,-590,-579,-570,-562,-549,-540,-537,-531,-527,-493,-479,-464,-456,-445,-429,-416,-415,-405,-400,-398,-372,-353,-332,-320,-313,-306,-299,-278,-226,-213,-204,-185,-175,-173,-131,-115,-114,-94,-93,-84,-82,-50,-31,-6,11,17,44,48,85,99,100,137,142,156,158,167,194,197,230,240,245,247,253,296,301,306,351,365,375,380,386,391,393,404,407,411,430,432,459,468,472,476,500,503,508,511,535,550,581,597,608,617,628,652,656,663,691,710,721,722,732,741,746,773,784,792,799,806,808,847,849,860,865,880,886,888,898,925,929,939,946,996,1014,1017,1055,1064,1068,1072,1076,1079,1102,1104,1123,1128,1145,1151,1152,1161,1163,1171,1200,1229,1231,1233,1234,1238,1243,1250,1256,1268,1296,1305,1321,1334,1336,1352,1371,1373,1375,1401,1405,1422,1429,1438,1447,1455,1475,1476,1483,1537,1548,1563,1564,1595,1601,1640,1681,1692,1693,1695,1708,1709,1718,1725,1726,1741,1747,1756,1789,1815,1818,1839,1840,1860,1869,1879,1884,1891,1900,1916,1934,1942,1972,1973,1986,1993,2003,2006,2008,2021,2037,2040,2049,2086,2093,2095,2096,2103,2104,2114,2118,2152,2162,2170,2180,2181,2189,2214,2216,2226,2234,2235,2242,2267,2272,2286,2302,2303,2311,2328,2334,2369,2372,2381,2386,2396,2444,2445,2465,2480,2518,2521,2529,2533,2537,2550,2581,2586,2590,2596,2606,2610,2627,2629,2632,2636,2653,2664,2685,2714,2726,2742,2744,2761,2791,2807,2819,2838,2854,2866,2927,2948,2972,2980,2985,3024,3039,3059,3074,3091,3094,3104,3205,3248,3249,3280,3294,3298,3354,3370,3386,3400,3414,3425,3426,3432,3436,3453,3462,3504,3527,3545,3548,3588,3591,3629,3633,3653,3673,3679,3683,3753,3774,3776,3784,3796,3798,3801,3802,3804,3817,3834,3844,3848,3855,3875,3882,3888,3902,3930,3964,3979,3983,3984,3992,4021,4044,4051,4082,4095,4106,4114,4119,4146,4156,4166,4167,4182,4204,4212,4220,4232,4289,4303,4324,4336,4353,4380,4393,4410,4435,4450,4454,4469,4498,4511,4525,4529,4556,4584,4585,4598,4671,4707,4726,4734,4738,4740,4751,4752,4777,4779,4781,4783,4788,4794,4805,4820,4826,4839,4856,4858,4863,4869,4897,4905,4914,4924,4935,4946,4956,4959,4980,4986,4988,4995,5021,5028,5033,5041,5073,5084,5105,5106,5109,5128,5130,5133,5136,5145,5221,5287,5333,5335,5347,5374,5379,5389,5398,5430,5449,5451,5452,5458,5468,5482,5486,5508,5514,5521,5539,5547,5555,5567,5594,5612,5620,5629,5649,5656,5659,5678,5680,5689,5704,5708,5716,5735,5745,5761,5763,5786,5798,5804,5833,5856,5859,5868,5887,5892,5918,5931,5954,5978,5985,5994,6010,6040,6050,6092,6103,6112,6114,6136,6140,6167,6168,6186,6250,6258,6264,6267,6291,6302,6344,6346,6353,6364,6368,6372,6377,6401,6430,6434,6447,6451,6459,6461,6467,6487,6493,6494,6512,6532,6540,6550,6584,6587,6643,6644,6660,6677,6707,6711,6718,6728,6731,6754,6758,6760,6794,6798,6814,6831,6865,6868,6889,6894,6912,6919,6920,6928,6940,6950,6977,7037,7069,7081,7088,7093,7102,7124,7132,7142,7147,7150,7170,7193,7205,7209,7224,7247,7254,7256,7278,7282,7324,7339,7364,7366,7368,7383,7386,7387,7398,7419,7469,7510,7538,7545,7560,7562,7578,7585,7599,7618,7645,7647,7662,7665,7672,7680,7682,7686,7705,7713,7736,7739,7749,7757,7769,7778,7785,7819,7820,7829,7846,7847,7858,7908,7913,7921,7949,7955,7956,7962,7963,7985,7992,7999,8002,8013,8034,8073,8087,8088,8099,8117,8180,8183,8191,8214,8218,8248,8263,8264,8270,8289,8290,8304,8321,8324,8369,8371,8380,8390,8432,8457,8466,8472,8490,8493,8501,8515,8529,8537,8545,8573,8577,8596,8617,8621,8644,8650,8671,8674,8678,8683,8692,8706,8735,8757,8759,8767,8781,8785,8800,8820,8836,8841,8882,8887,8899,8904,8919,8923,8935,8936,8942,8972,8987,9016,9033,9035,9066,9080,9083,9085,9088,9093,9097,9124,9131,9166,9171,9180,9212,9233,9241,9252,9325,9329,9345,9355,9356,9371,9382,9385,9399,9415,9434,9438,9453,9460,9478,9488,9492,9523,9547,9549,9553,9554,9574,9584,9594,9633,9640,9655,9669,9682,9719,9722,9735,9737,9745,9748,9804,9811,9856,9864,9865,9879,9890,9891,9901,9903,9930,10000]
target = -3774
Case 33
nums = [-199,-186,-176,-174,-148,-139,-128,-124,-108,-99,-95,-94,-57,-49,-20,-17,-13,15,21,27,28,29,41,44,50,58,60,70,77,78,83,86,123,124,126,130,167,168,185,195]
target = -200
Case 34
nums = [-199,-186,-176,-174,-148,-139,-128,-124,-108,-99,-95,-94,-57,-49,-20,-17,-13,15,21,27,28,29,41,44,50,58,60,70,77,78,83,86,123,124,126,130,167,168,185,195]
target = 196
Case 35
nums = [-199,-186,-176,-174,-148,-139,-128,-124,-108,-99,-95,-94,-57,-49,-20,-17,-13,15,21,27,28,29,41,44,50,58,60,70,77,78,83,86,123,124,126,130,167,168,185,195]
target = 16