6 kyu

Closest Sum

322 of 566smepple

Description:

Given an array (ints) of n integers, find three integers in arr such that the sum is closest to a given number (num), target.

Return the sum of the three integers. You may assume that each input would have exactly one solution.

Example:

closest_sum([-1, 2, 1, -4], 1) # 2 (-1 + 2 + 1 = 2)

Note: your solution should not modify the input array.

Fundamentals

More By Author:

Check out these other kata created by smepple

Stats:

CreatedJul 7, 2016
PublishedJul 7, 2016
Warriors Trained1393
Total Skips40
Total Code Submissions4508
Total Times Completed566
Ruby Completions86
Python Completions322
JavaScript Completions179
CoffeeScript Completions9
Haskell Completions16
Total Stars30
% of votes with a positive feedback rating86% of 167
Total "Very Satisfied" Votes130
Total "Somewhat Satisfied" Votes28
Total "Not Satisfied" Votes9
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • smepple Avatar
  • jhoffner Avatar
  • cliffstamp Avatar
  • saudiGuy Avatar
Ad