diff --git a/README.md b/README.md index ac1ddf7..b244636 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ in C++, Java and Python. ||[Counting Valleys](https://www.hackerrank.com/challenges/counting-valleys/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup)|[Done](/Warm-Up%20Challenges/counting_valleys.cpp)|[Done](/Warm-Up%20Challenges/countingValleys.java)|[Done](/Warm-Up%20Challenges/CountingValleys.py)| ||[Jumping on the Clouds](https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup)|[Done](/Warm-Up%20Challenges/Jumping_on_the_clouds.cpp)|[Done](/Warm-Up%20Challenges/jumpingOnTheClouds.java)|[Done](/Warm-Up%20Challenges/JumpingOnTheClouds.py)| ||[Repeated Strings](https://www.hackerrank.com/challenges/repeated-string/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup)|[Done](/Warm-Up%20Challenges/repeated_string.cpp)|[Done](/Warm-Up%20Challenges/repeatedString.java)|[Done](/Warm-Up%20Challenges/RepeatedStrings.py)| +||[Birthday Cake Candles](https://www.hackerrank.com/challenges/birthday-cake-candles/problem)|[Done](/Warm-Up%20Challenges/Birthday%20Cake%20Candle.cpp)||| |Arrays | | | | | ||[Arrays: Left Rotation](https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays)|[Done](https://github.com/maze-runnar/interview-preparation-kit/blob/master/Arrays/array_left_rotation.cpp)|[Done](https://github.com/maze-runnar/interview-preparation-kit/blob/master/Arrays/LeftRotation.java)|[Done](/Arrays/LeftRotation.py)| ||[New Year Chaos](https://www.hackerrank.com/challenges/new-year-chaos/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays)|[Done](https://github.com/maze-runnar/interview-preparation-kit/blob/master/Arrays/new_year_chaos.cpp)|[Done](https://github.com/maze-runnar/interview-preparation-kit/blob/master/Arrays/NewYearChaos.java)|[Done](/Arrays/NewYearChaos.py)| diff --git a/Warm-Up Challenges/Birthday Cake Candle.cpp b/Warm-Up Challenges/Birthday Cake Candle.cpp new file mode 100644 index 0000000..1a0e312 --- /dev/null +++ b/Warm-Up Challenges/Birthday Cake Candle.cpp @@ -0,0 +1,116 @@ +/*You are in charge of the cake for your niece's birthday and have decided the cake will have one candle for each year of her total age. When she blows out the candles, she’ll only be able to blow out the tallest ones. Your task is to find out how many candles she can successfully blow out. + +For example, if your niece is turning years old, and the cake will have candles of height , , , , she will be able to blow out candles successfully, since the tallest candles are of height and there are such candles. + +Function Description + +Complete the function birthdayCakeCandles in the editor below. It must return an integer representing the number of candles she can blow out. + +birthdayCakeCandles has the following parameter(s): + +ar: an array of integers representing candle heights +Input Format + +The first line contains a single integer, , denoting the number of candles on the cake. +The second line contains space-separated integers, where each integer describes the height of candle . + +Input +4 +3 2 1 3 + +Output Format +2 + +Return the number of candles that can be blown out on a new line.*/ + +#include + +using namespace std; + +vector split_string(string); + +// Complete the birthdayCakeCandles function below. +int birthdayCakeCandles(vector ar) + { + int largest=ar[0]; + int count=0; + + for(int i=1;ilargest) + { + largest=ar[i]; + } + } + + for(int i=0;i> ar_count; + cin.ignore(numeric_limits::max(), '\n'); + + string ar_temp_temp; + getline(cin, ar_temp_temp); + + vector ar_temp = split_string(ar_temp_temp); + + vector ar(ar_count); + + for (int i = 0; i < ar_count; i++) { + int ar_item = stoi(ar_temp[i]); + + ar[i] = ar_item; + } + + int result = birthdayCakeCandles(ar); + + fout << result << "\n"; + + fout.close(); + + return 0; +} + +vector split_string(string input_string) { + string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { + return x == y and x == ' '; + }); + + input_string.erase(new_end, input_string.end()); + + while (input_string[input_string.length() - 1] == ' ') { + input_string.pop_back(); + } + + vector splits; + char delimiter = ' '; + + size_t i = 0; + size_t pos = input_string.find(delimiter); + + while (pos != string::npos) { + splits.push_back(input_string.substr(i, pos - i)); + + i = pos + 1; + pos = input_string.find(delimiter, i); + } + + splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1)); + + return splits; +}