Short Problem Definition: Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty. Link Compare Triplets Complexity: time complexity is O(1) space complexity is O(1) Execution: This is a warmup. Follow specification. Solution: [rust]use...

## HackerRank âCommon Childâ Solution

Short Problem Definition: Given two strings a and b of equal length, whatâs the longest string (S) that can be constructed such that it is a child of both? A string x is said to be a child of a string y if x can be formed by deleting 0 or more characters from y. Link Common Child Complexity: time complexity is O(N*M) space complexity is O(N*M) Execution: This is a longest common subsequence...

## 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...

## 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 â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 â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 âChocolate Feastâ Solution

Short Problem Definition: Little Bob loves chocolates, and goes to a store with $N in his pocket. The price of each chocolate is $C. The store offers a discount: for every M wrappers he gives to the store, he gets one chocolate for free. How many chocolates does Bob get to eat? Link Chocolate Feast Complexity: time complexity is O(N); space complexity is O(1) Execution: Evaluate the number of...

## HackerRank âCavity Mapâ Solution

Short Problem Definition: You are given a square map of size nĂn. Each cell of the map has a value denoting its depth. We will call a cell of the map a cavity if and only if this cell is not on the border of the map and each cell adjacent to it has strictly smaller depth. Two cells are adjacent if they have a common side. Link Cavity Map Complexity: time complexity is O(N^2) space complexity is...

## HackerRank âCats And A Mouseâ Solution

Short Problem Definition: Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse doesnât move and the cats travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will escape while they fight. Link Cats And A Mouse...

## HackerRank âCastle on the Gridâ Solution

Short Problem Definition: You are given a grid with both sides equal to N/N. Rows and columns are numbered from 0/0 to Nâ1/Nâ1. There is a castle on the intersection of the aath row and the bbth column. Your task is to calculate the minimum number of steps it would take to move the castle from its initial position to the goal position (c/d). It is guaranteed that it is possible to reach the goal...