From 03af4ae83fcca76ff82a77718a3e718a54e597d3 Mon Sep 17 00:00:00 2001 From: sakshi gaur <44137767+gaursakshi@users.noreply.github.com> Date: Thu, 26 Dec 2019 15:07:51 +0530 Subject: [PATCH 1/7] Create Birthday Cake Candle.cpp --- Warm-Up Challenges/Birthday Cake Candle.cpp | 116 ++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Warm-Up Challenges/Birthday Cake Candle.cpp 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; +} From f11edc37ff17305a2cbb6436c8dd9790ac4d93c3 Mon Sep 17 00:00:00 2001 From: sakshi gaur <44137767+gaursakshi@users.noreply.github.com> Date: Thu, 26 Dec 2019 16:01:19 +0530 Subject: [PATCH 2/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cb33749..804d0ef 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 Cake Candle.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)| From e677a18e2cce2365193a8ca11d60592c75ece877 Mon Sep 17 00:00:00 2001 From: sakshi gaur <44137767+gaursakshi@users.noreply.github.com> Date: Thu, 26 Dec 2019 16:01:48 +0530 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 804d0ef..57a8f2d 100644 --- a/README.md +++ b/README.md @@ -12,7 +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 Cake Candle.cpp)| +||[Birthday Cake Candles](https://www.hackerrank.com/challenges/birthday-cake-candles/problem)|[Done] |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)| From 18543665ed027e2c87b32efbbafd4a3e6f592bf5 Mon Sep 17 00:00:00 2001 From: sakshi gaur <44137767+gaursakshi@users.noreply.github.com> Date: Thu, 26 Dec 2019 16:02:12 +0530 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57a8f2d..8feeb6c 100644 --- a/README.md +++ b/README.md @@ -12,7 +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] +||[Birthday Cake Candles](https://www.hackerrank.com/challenges/birthday-cake-candles/problem)| |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)| From ff06f6ec96b3734ddd819068088ed6a9807a69fc Mon Sep 17 00:00:00 2001 From: sakshi gaur <44137767+gaursakshi@users.noreply.github.com> Date: Thu, 26 Dec 2019 17:17:06 +0530 Subject: [PATCH 5/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8feeb6c..9751d44 100644 --- a/README.md +++ b/README.md @@ -12,7 +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)| +||[Birthday Cake Candles](https://www.hackerrank.com/challenges/birthday-cake-candles/problem)|[Done](/Warm-Up Challenges/Birthday Cake Candle.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)| From e1e9dfaf618e80d2736dfa0e890ee7d1b5a6e565 Mon Sep 17 00:00:00 2001 From: sakshi gaur <44137767+gaursakshi@users.noreply.github.com> Date: Thu, 26 Dec 2019 17:18:47 +0530 Subject: [PATCH 6/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9751d44..6dc72cf 100644 --- a/README.md +++ b/README.md @@ -12,7 +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 Challenges/Birthday Cake Candle.cpp)| +||[Birthday Cake Candles](https://www.hackerrank.com/challenges/birthday-cake-candles/problem)|[Done](/Warm-Up Challenges/Birthday Cake Candle.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)| From c35b938b45f90f0277f65bed91c43c9b91a77f06 Mon Sep 17 00:00:00 2001 From: Shiv Kumar Date: Thu, 26 Dec 2019 17:29:22 +0530 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6dc72cf..2c273fa 100644 --- a/README.md +++ b/README.md @@ -12,7 +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 Challenges/Birthday Cake Candle.cpp)|| +||[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)|