7 kyu

Minimum Steps (Array Series #6)

556 of 7,030MrZizoScream

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

Fundamentals
Arrays

Stats:

CreatedFeb 24, 2018
PublishedFeb 24, 2018
Warriors Trained10798
Total Skips522
Total Code Submissions24770
Total Times Completed7030
C++ Completions556
Ruby Completions201
JavaScript Completions2490
Python Completions2081
Crystal Completions13
Haskell Completions93
C Completions147
Java Completions776
PHP Completions183
Dart Completions236
Julia Completions17
TypeScript Completions178
CoffeeScript Completions14
Scala Completions102
Elixir Completions41
Reason Completions7
Prolog Completions20
Clojure Completions27
Rust Completions245
COBOL Completions5
Total Stars106
% of votes with a positive feedback rating91% of 1101
Total "Very Satisfied" Votes938
Total "Somewhat Satisfied" Votes136
Total "Not Satisfied" Votes27
Total Rank Assessments31
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • MrZizoScream Avatar
  • GiacomoSorbi Avatar
  • Chrono79 Avatar
  • imjasonmiller Avatar
  • B1ts Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • rsa Avatar
  • clcraig Avatar
  • FArekkusu Avatar
  • monadius Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • stellartux Avatar
  • username0 Avatar
  • user8436785 Avatar
  • oybek Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad