Hackerrank Electronic Shop (C++)
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: 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...
C++ : Explanation: First, a frequency vector of size 5 is initialized to all 0s. For each type of bird in arr, count the frequency of the bird in the first for loop....
C++ : Explanation: This is about adding two numbers at ar[i] and ar[j], such that the sum is divisible by k. n is the ar.size(), which is actually no need to be provided,...