Minimum Steps (Array Series #6)
Description:
Task
Given an array of N integers, you have to find how many times you have to add up the smallest numbers in the array until their Sum becomes greater or equal to K.
Notes:
List size is at least 3.
All numbers will be positive.
Numbers could occur more than once , (Duplications may exist).
Threshold K will always be reachable.
Input >> Output Examples
minimumSteps({1, 10, 12, 9, 2, 3}, 6) ==> return (2)
Explanation:
We add two smallest elements (1 + 2), their sum is 3 .
Then we add the next smallest number to it (3 + 3) , so the sum becomes 6 .
Now the result is greater or equal to 6 , Hence the output is (2) i.e (2) operations are required to do this .
minimumSteps({8 , 9, 4, 2}, 23) ==> return (3)
Explanation:
We add two smallest elements (4 + 2), their sum is 6 .
Then we add the next smallest number to it (6 + 8) , so the sum becomes 14 .
Now we add the next smallest number (14 + 9) , so the sum becomes 23 .
Now the result is greater or equal to 23 , Hence the output is (3) i.e (3) operations are required to do this .
minimumSteps({19,98,69,28,75,45,17,98,67}, 464) ==> return (8)
Explanation:
We add two smallest elements (19 + 17), their sum is 36 .
Then we add the next smallest number to it (36 + 28) , so the sum becomes 64 .
We need to keep doing this until the sum becomes greater or equal to K (464 in this case), which will require 8 Steps .
Expected Time Complexity
O(n Log n)
Playing with Numbers Series
Playing With Lists/Arrays Series
For More Enjoyable Katas
ALL translations are welcomed
Enjoy Learning !!
Zizou
Similar Kata:
Stats:
Created | Feb 24, 2018 |
Published | Feb 24, 2018 |
Warriors Trained | 10798 |
Total Skips | 522 |
Total Code Submissions | 24770 |
Total Times Completed | 7030 |
C++ Completions | 556 |
Ruby Completions | 201 |
JavaScript Completions | 2490 |
Python Completions | 2081 |
Crystal Completions | 13 |
Haskell Completions | 93 |
C Completions | 147 |
Java Completions | 776 |
PHP Completions | 183 |
Dart Completions | 236 |
Julia Completions | 17 |
TypeScript Completions | 178 |
CoffeeScript Completions | 14 |
Scala Completions | 102 |
Elixir Completions | 41 |
Reason Completions | 7 |
Prolog Completions | 20 |
Clojure Completions | 27 |
Rust Completions | 245 |
COBOL Completions | 5 |
Total Stars | 106 |
% of votes with a positive feedback rating | 91% of 1101 |
Total "Very Satisfied" Votes | 938 |
Total "Somewhat Satisfied" Votes | 136 |
Total "Not Satisfied" Votes | 27 |
Total Rank Assessments | 31 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |