Short Problem Definition: Happy Ladybugs is a board game having the following properties: A ladybug is happy only when it’s left or right adjacent cell (i.e., ) b[i+/-1] is occupied by another ladybug having the same color. Link Happy Ladybugs Complexity: time complexity is O(N) space complexity is O(1) Execution: This challenge definition does not require a full sort. It only wants to know...

## HackerRank ‘Drawing Book’ Solution

Short Problem Definition: Brie’s Drawing teacher asks her class to open their books to a page number. Brie can either start turning pages from the front of the book or from the back of the book. She always turns pages one at a time. When she opens the book, page 1 is always on the right side. Link Drawing Book Complexity: time complexity is O(1) space complexity is O(1) Execution: Integral...

## HackerRank ‘Electronics Shop’ Solution

Short Problem Definition: Monica wants to buy a keyboard and a USB drive from her favorite electronics store. The store has several models of each. Monica wants to spend as much as possible for the 2 items, given her budget. Given the price lists for the store’s keyboards and USB drives, and Monica’s budget, find and print the amount of money Monica will spend. If she doesn’t have enough money to...

## HackerRank ‘Encryption’ Solution

Short Problem Definition: An English text needs to be encrypted using the following encryption scheme.First, the spaces are removed from the text. Let L be the length of this text. Link Encryption Complexity: time complexity is O(n) space complexity is O(1) Execution: You do not need to create all the arrays. Just work with an offset and array slices. Solution: 1 2 3 4 5 6 7 8 #!/usr/bin/py from...

## HackerRank ‘Circle City’ Solution

Short Problem Definition: Roy lives in a city that is circular in shape on a 2D plane that has radius r. The city center is located at origin (0,0) and it has suburbs lying on the lattice points (points with integer coordinates). The city Police Department Headquarters can only protect those suburbs which are located strictly inside the city. The suburbs located on the border of the city are...

## HackerRank ‘Fair Rations’ Solution

Short Problem Definition: You are the benevolent ruler of Rankhacker Castle, and today you’re distributing bread. Your subjects are in a line, and some of them already have some loaves. Times are hard and your castle’s food stocks are dwindling, so you must distribute as few loaves as possible according to the following rules: Every time you give a loaf of bread to some person i...

## HackerRank ‘Circular Array Rotation’ Solution

Short Problem Definition: John Watson performs an operation called a right circular rotation on an array of integers. Link Circular Array Rotation Complexity: time complexity is O(Q) space complexity is O(1) Execution: Calculate the offset for every query. Watch out for index overflows and negative modulo. Solution: [rust]use std::io; fn get_number() -> u32 { let mut line = String::new();...

## HackerRank ‘Find Digits’ Solution

Short Problem Definition: You are given an integer N. Find the digits in this number that exactly divide N (division that leaves 0 as remainder) and display their count. For N=24, there are 2 digits (2 & 4). Both of these digits exactly divide 24. So our answer is 2. Link Find Digits Complexity: time complexity is O(N); space complexity is O(1) Execution: Just follow the problem description. The...

## HackerRank ‘Climbing The Leatherboard’ Solution

Short Problem Definition: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ranking. The game uses Dense Ranking, so its leaderboard works like this: The player with the highest score is ranked number 1 on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately...

## HackerRank ‘Closest Numbers’ Solution

Short Problem Definition: Given a list of unsorted integers, A={a1,a2,…,aN}, can you find the pair of elements that have the smallest absolute difference between them? If there are multiple pairs, find them all. Link Closest Numbers Complexity: time complexity is O(n*log(n)) // sorting space complexity is O(n) Execution: Just sort the array and print the smallest difference. Solution: 1 2 3 4 5 6...