View on GitHub

hackerrank

HackerRank personal solutions

Algorithms

The true test of problem solving: when one realizes that time and memory aren’t infinite.

Warmup

Name Preview Code Difficulty
Solve Me First This is an easy challenge to help you start coding in your favorite languages! C++ Haskell Java Javascript Python bash Easy
Simple Array Sum Calculate the sum of integers in an array. C++ Python Easy
Compare the Triplets Compare the elements in two triplets. C++ Python Easy
A Very Big Sum Calculate the sum of the values in an array that might exceed the range of int values. Python Easy
Diagonal Difference Calculate the absolute difference of sums across the two diagonals of a square matrix. Python Easy
Plus Minus Calculate the fraction of positive, negative and zero values in an array. Python Easy
Staircase Print a right-aligned staircase with n steps. Python Easy
Mini-Max Sum Find the maximum and minimum values obtained by summing four of five integers. Python Easy
Birthday Cake Candles Determine the number of candles that are blown out. Python Easy
Time Conversion Convert time from an AM/PM format to a 24 hour format. Python Easy

Implementation

Name Preview Code Difficulty
Grading Students Round student grades according to Sam’s rules. Python Easy
Apple and Orange Find the respective numbers of apples and oranges that fall on Sam’s house. Python Easy
Kangaroo Can two kangaroo meet after making the same number of jumps? Python Easy
Between Two Sets Find the number of integers that satisfies certain criteria relative to two sets. Python Easy
Breaking the Records Given an array of Maria’s basketball scores all season, determine the number of times she breaks her best and worst records. Python Easy
Birthday Chocolate Given an array of integers, find the number of subarrays of length k having sum s. Python Easy
Divisible Sum Pairs Count the number of pairs in an array having sums that are evenly divisible by a given number. Python Easy
Migratory Birds Determine which type of bird in a flock occurs at the highest frequency. Python Easy
Day of the Programmer Given year, determine date of the 256th day of the year. Python Easy
Bon Appétit Determine whether or not Brian overcharged Anna for their split bill. Python Easy
Sock Merchant How many pairs of socks John can sell? Python Easy
Drawing Book How many pages does Brie need to turn to get to page p? Python Easy
Counting Valleys Count the valleys encountered during vacation. C++ Easy
Electronics Shop Determine the most expensive Keyboard and USB drive combination Monica can purchase within her budget. C++ Easy
Cats and a Mouse Which cat will catch the mouse first? Python Easy
Forming a Magic Square Find the minimum cost of converting a 3 by 3 matrix into a magic square. Python Medium
Picking Numbers What’s the largest size subset can you choose from an array such that the difference between any two integers is not bigger than 1? Python Easy
Climbing the Leaderboard Help Alice track her progress toward the top of the leaderboard! Python Medium
The Hurdle Race Can you help Dan determine the minimum number of magic beverages he must drink to jump all the hurdles? Python Easy
Designer PDF Viewer Help finding selection area in PDF Viewer. Python Easy
Utopian Tree Predict the height of the tree after N growth cycles. Python Easy
Angry Professor Decide whether or not the class will be canceled based on the arrival times of its students. Python Easy
Beautiful Days at the Movies Find the number of beautiful days. Python Easy
Viral Advertising How many people will know about the new product after n days? Python Easy
Save the Prisoner! Given M sweets and a circular queue of N prisoners, find the ID of the last prisoner to receive a sweet. Python Easy
Circular Array Rotation Print the elements in an array after ‘m’ right circular rotation operations. Python Easy
Sequence Equation Find some y satisfying p(p(y)) = x for each x from 1 to n. Python Easy
Jumping on the Clouds: Revisited Determine the amount of energy Aerith has after the cloud game ends. Python Easy
Find Digits Calculate the number of digits in an integer that evenly divide it. Python Easy
Extra Long Factorials Calculate a very large factorial that doesn’t fit in the conventional numeric data types. Haskell Python Medium
Append and Delete Can you convert $s$ to $t$ by performing exactly $k$ operations? Python Easy
Sherlock and Squares Find the count of square numbers between A and B Python Easy
Library Fine Help your library calculate fees for late books! Python Easy
Cut the sticks Given the lengths of n sticks, print the number of sticks that are left before each cut operation. Python Easy
Non-Divisible Subset Find the size of the maximal non-divisible subset. Python Medium
Repeated String Find and print the number of letter a’s in the first n letters of an infinitely large periodic string. Python Easy
Jumping on the Clouds Jumping on the clouds Python Easy
Equalize the Array Delete a minimal number of elements from an array so that all elements of the modified array are equal to one another. Python Easy
Queen’s Attack II Find the number of squares the queen can attack. Python Medium
ACM ICPC Team Print the maximum topics a given team can cover for ACM ICPC World Finals Python Easy
Taum and B’day Calculate the minimum cost required to buy some amounts of two types of gifts when costs of each type and the rate of conversion from one form to another is provided. Python Easy
Organizing Containers of Balls Determine if David can perform some sequence of swap operations such that each container holds one distinct type of ball. Python Medium
Encryption Encrypt a string by arranging the characters of a string into a matrix and printing the resulting matrix column wise. Python Medium
Bigger is Greater Rearrange the letters of a string to construct another string such that the new string is lexicographically greater than the original. Python Medium
Modified Kaprekar Numbers Print kaprekar numbers in the given range Python Easy
Beautiful Triplets   Python Easy
Minimum Distances Find the minimum distance between two different indices containing the same integers. Python Easy
Halloween Sale How many games can you buy during the Halloween Sale? Python Easy
The Time in Words Display the time in words. Python Medium
Chocolate Feast Calculate the number of chocolates that can be bought following the given conditions. Python Easy
Service Lane Calculate the maximum width of the vehicle that can pass through a service lane. Python Easy
Lisa’s Workbook A workbook with chapters. Some number of problems per page. How many problems have a number equal to a page’s number? Python Easy
Flatland Space Stations Find the maximum distance an astronaut needs to travel to reach the nearest space station. Python Easy
Fair Rations How many loaves of bread will it take to feed your subjects? Python Easy
Cavity Map Depict cavities on a square map C++ Easy
Manasa and Stones Calculate the possible values of the last stone where consecutive values on the stones differ by a value ‘a’ or a value ‘b’. Python Easy
The Grid Search Given a 2D array of digits, try to find a given 2D grid pattern of digits within it. Python Medium
Happy Ladybugs Determine whether or not all the ladybugs can be made happy. Python Easy
Strange Counter Print the value displayed by the counter at a given time, $t$. Python Easy
Absolute Permutation Find lexicographically smallest absolute permutation. Python Medium
Ema’s Supercomputer Determine the product of the areas of two pluses on a grid. C++ Medium
Larry’s Array Larry Python Medium
Almost Sorted Sort an array by either swapping or reversing a segment Python Medium
Matrix Layer Rotation Rotate the matrix R times and print the resultant matrix. Python Hard

Strings

Name Preview Code Difficulty
Super Reduced String Given a string, repeatedly remove adjacent pairs of matching characters and then print the reduced result. Python Easy
CamelCase   Python Easy
Strong Password How many characters should you add to make the password strong? Python Easy
Two Characters Print the length of the longest possible string $t$ you can form. Python Easy
Caesar Cipher Encrypt a string by rotating the alphabets by a fixed value in the string. Python Easy
Mars Exploration Save Our Ship! Python Easy
HackerRank in a String! Determine if a string contains a subsequence of characters that spell “hackerrank”. Python Easy
Pangrams Check whether a given string is a panagram or not. Python Easy
Weighted Uniform Strings Determine if a string contains uniform substrings of certain weights. Python Easy
Separate the Numbers Determine if a numeric string can be broken into a sequence of increasing numbers. Python Easy
Funny String Is the absolute difference between consecutive characters is the same for a string and the reverse of that string for all indices. Python Easy
Gemstones Find the number of different gem-elements present. Python Easy
Alternating Characters Calculate the minimum number of deletions required to convert a string into a string in which consecutive characters are different. Python Easy
Beautiful Binary String How many binary characters must you change to remove every occurrence of “010” from a binary string? Python Easy
The Love-Letter Mystery Find the minimum number of operations required to convert a given string into a palindrome under certain conditions Python Easy
Determining DNA Health Determine which weighted substrings in a subset of substrings can be found in a given string and calculate the string’s total weight. Python Hard
Palindrome Index Determine which character(s) must be removed to make a string a palindrome. Python Easy
Anagram Find the minimum number of characters of the first string that we need to change in order to make it an anagram of the second string. Python Easy
Making Anagrams How many characters should one delete to make two given strings anagrams of each other? Python Easy
Game of Thrones - I Check whether any anagram of a string can be a palindrome or not. Python Easy
Two Strings Given two strings, you find a common substring of non-zero length. Python Easy
String Construction Find the minimum cost of copying string s. Python Easy
Sherlock and the Valid String Remove some characters from the string such that the new string’s characters have the same frequency. Python Medium
Highest Value Palindrome Make a number palindromic in no more than $k$ moves, maximal. Python Medium
Sherlock and Anagrams Find the number of unordered anagramic pairs of substrings of a string. Python Medium
Common Child Given two strings a and b of equal length, what’s the longest string (s) that can be constructed such that s is a child to both a and b? C++ Python Medium
Morgan and a String Find the lexicographically minimal string that can be formed by the combination of two strings. C Expert

Sorting

Name Preview Code Difficulty
Big Sorting Sort an array of very long numeric strings. Python Easy
Intro to Tutorial Challenges Introduction to the Tutorial Challenges Python Easy
Insertion Sort - Part 1 Insert an element into a sorted array. Python Easy
Insertion Sort - Part 2 Code Insertion Sort itself. Python Easy
Correctness and the Loop Invariant How do you demonstrate the correctness of an algorithm? You can use the loop invariant. Python Easy
Running Time of Algorithms The running time of Algorithms in general and Insertion Sort in particular. Python Easy
Quicksort 1 - Partition Perform the first step of Quicksort: partitioning an array. Python Easy
Counting Sort 1 Count the number of times each value appears. Python Easy
Counting Sort 2 Simple version of counting sort. Python Easy
The Full Counting Sort The real counting sort. Python Medium
Closest Numbers Find the closest numbers in a list. Python Easy
Find the Median Find the Median in a list of numbers. Python Easy
Insertion Sort Advanced Analysis How many shifts will it take Insertion Sort to sort an array? C++ Python Advanced
Name Preview Code Difficulty
Hackerland Radio Transmitters Find the minimum number of radio transmitters needed to cover all the houses in Hackerland! Python Medium
Ice Cream Parlor Help Sunny and Johnny spend all their money during each trip to the Ice Cream Parlor. Python Easy
Missing Numbers Find the numbers missing from a sequence given a permutation of the original sequence Python Easy
Pairs Given N numbers, count the total pairs of numbers that have a difference of K. Python Medium
Sherlock and Array Check whether there exists an element in the array such that sum of elements on its left is equal to the sum of elements on its right. Python Easy

Greedy

Name Preview Code Difficulty
Minimum Absolute Difference in an Array Given a list of integers, calculate their differences and find the difference with the smallest absolute value. Python Easy
Marc’s Cakewalk Find the minimum number of miles Marc must walk to burn the calories consumed from eating cupcakes. Python Easy
Grid Challenge Find if it is possible to rearrange a square grid such that every row and every column is lexicographically sorted. Python Easy
Maximum Perimeter Triangle Find the triangle having the maximum perimeter. C++ Easy
Beautiful Pairs Change an element of B and calculate the number of pairwise disjoint beautiful pairs. Python Easy
Sherlock and The Beast Find the largest number following some rules having N digits. Python Easy

Dynamic Programming

Name Preview Code Difficulty
Fibonacci Modified Compute the nth term of a Fibonacci sequence. Python Medium
The Longest Increasing Subsequence Find the length of the longest increase subsequence in a given array. C++ Advanced
Dorsey Thief standard knapsack problem C++ Advanced

Constructive Algorithms

Name Preview Code Difficulty
New Year Chaos Determine how many bribes took place to get a queue into its current state. Python Medium

Bit Manipulation

Name Preview Code Difficulty
Lonely Integer Find the unique element in an array of integer pairs. Python Easy
Maximizing XOR Given two integers, L and R, find the maximal value of A xor B, where A and B satisfy a condition. Python Easy
Counter game Louise and Richard play a game, find the winner of the game. Python Medium
The Great XOR Count the number of non-negative integer a’s that are less than some x where the bitwise XOR of a and x is greater than x. C++ Medium
Flipping bits Flip bits in its binary representation. C++ Easy
A or B A or B = C Python Medium
Hamming Distance You are given a string S, consisting of N small latin letters ‘a’ and ‘b’. Process the given M queries. C++ Expert

Game Theory

Name Preview Code Difficulty
Game of Stones A Game of Stones Python Easy

Debugging

Name Preview Code Difficulty
Prime Dates Find the number of prime dates in a range C++ Java Python Medium
Zig Zag Sequence Find a zig zag sequence of the given array. C++ Java Python Medium