# Latest stories

## HackerRank âCompare Tripletsâ Solution

H

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

H

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

H

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

H

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

H

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

H

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

H

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

H

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

H

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

H

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