Hackerrank Minimum Distances (C++)
C++ : Explanation: First, assign a large number to maxInt and assign it to minDist. In this case, we use the largest possible int, 2,147,483,647. Using a double nested for loop, loop through...
C++ : Explanation: First, assign a large number to maxInt and assign it to minDist. In this case, we use the largest possible int, 2,147,483,647. Using a double nested for loop, loop through...
Java : Explanation: First, sort the array so that counting the number of repeated elements in the array is easier. After sorting, assign the first element of the array arr[0] to prevInt. countInt...
C++ : Explanation: First, check if y2 is greater than y1. If yes, it means the book was returned at a non expired date, and fineAmount is set to 0. Else, if the...
Java : Explanation: Warning: Lots of converting from ArrayLists to Arrays and vice versa ahead! First, convert the ArrayList sticks to store the number of sticks left after each cut-and-throw round. Add the...
Java : Explanation: This is a fun question. At first sight, the idea to answer this would be to take the range of numbers from a to b, and run a for loop...
Java : Explanation: This question is so much easier done in Java, since Java has the BigInteger class that supports huge numbers. Another language that supports these big numbers is Ruby. The for...
C++ : Explanation: This question involved rotating the elements in a vector. The good thing is, C++ has a nice little in-built function to do that. First, we take mod k by a.size(),...
C++ : Explanation: This question basically deals with getting individual digits from a number with mod (%) and integer division. In the while loop, we will loop till nHolder (temporary holder for n)...
C++ : Explanation: Note: Test case 8 (Test case 1 in Run Code, Test case 8 in Submit Code) is bugged! I spend hours trying to cater to test case 8 but to...
C++ : Explanation: Note: This is a terrible, terrible solution. Look at the number of nested loops! Yes, it works, but loopsss! The question was not easy to understand, so the breakdown is...