Hackerrank Save the Prisoner! (C++)
C++ : Explanation: It is tempting to simply use an outer for loop (to pass candy around the prisoners), then followed by an inner while loop (to subtract prisoners after each round if...
C++ : Explanation: It is tempting to simply use an outer for loop (to pass candy around the prisoners), then followed by an inner while loop (to subtract prisoners after each round if...
C++ : Explanation: At first glance, this question feels like a pyramid scheme. The for loop in this case does exactly like what the question says: It first gets the number of likes...
C++ : Explanation: Using the supplied i and j in the for loop, for each i smaller or equal to j, set day = i and reverseDay = 0. Each number will need...
C++ : Explanation: This one is simply. Set the return string cancelled to “YES” as default, and number of on time student onTime to 0. For each element in vector a, if the...
C++ : Explanation: When receiving the height of the tree, the most outer if loop checks if n is equal to 0, if it is, the default height, which is 1, is returned....
C++ : Explanation: We need a string of all alphabets to determine the height of each alphabet in word for this one, and store it in variable alphabetList. In the for loop, for...
C++ : Explanation: Ok, this one had me debugging for some time due to the “Terminated due to timeout” status on Hackerrank. It was frustrating when all the smaller test cases passed but...
C++ : Explanation: First, find the max height of the hurdles in the race. Assign it to maxHeight. Then find the number of times Dan has to drink the potion by maxHeight –...
C++ : Explanation: For the outer for loop (iterating with i), each ith element is assigned to startingNo. We then decide to look for the number smaller or larger than startingNo, depending on...
C++ : Explanation: This one is cute. Reminds me of Tom and Jerry, or in this case Toms and Jerry. First, check if either Tom A, Tom B, or Jerry has met. Either...