Hackerrank Picking Numbers (C++)
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: 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...
C++ : Explanation: This one is simple. Simply do a nested for loop to loop through all the prices combination of keyboard and drives. Set the amountSpent to -1 if it’s over the...
C++ : Explanation: Set both noOfPagesToTurn and temp variables to 0. The first if checks if the page to turn to is 1, the last page n, or if the book has odd...
Javascript : Explanation: At first glance, this seems like a very simple problem. Simply repeat string s for n times, then use substring to find the number of ‘a’ that appears. This works...
Javascript : Explanation: The first if statement takes care of the corner case of 2 elements in c, such that it will always at least have 1 jump (actually, a do while loop...
Javascript : Explanation: For the first step of Gary’s hike, check if it is above or below sea level, if it < 0, add 1 to noOfValleys (Entering a valley in his 1st...
C++ : Explanation: Sort the socks with sort(). (Try saying this 10 times quickly.) The for loop finds pairs of socks with the same numbers, and add 1 to noOfSockPairs each time a...
C++ : Explanation: The for loop sums up all elements of the vector bill except the element at k and put it in billToSplit. billToSplit is then divided by Brian and Anna. After...
C++ : Explanation: Happy Russian birthday programmers! This is a fun one. First, check for leap years in both the Julian and Gregorian calendars in the during or before 1917, and the years...