CategoryCoding Challenge

HackerRank ā€˜Fair Rationsā€™ Solution

H

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

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 ā€˜Find Digitsā€™ Solution

H

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

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 ā€˜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 ā€˜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 ā€˜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 ā€˜Count Luckā€™ Solution

H

Short Problem Definition: Hermione Granger is lost in the Forbidden Forest while collecting some herbs for a magical potion. The forest is magical and has only one exit point, which magically transports her back to the Hogwarts School of Witchcraft and Wizardry. Link Count Luck Complexity: time complexity is O(n) space complexity is O(n) Execution: I solve this challenge using DFS and dynamic...

HackerRank ā€˜Counter Gameā€™ Solution

H

Short Problem Definition: Louise and Richard play a game. They have a counter set to N. Louise gets the first turn and the turns alternate thereafter. In the game, they perform the following operations. If N is not a power of 2, reduce the counter by the largest power of 2 less than N. If N is a power of 2, reduce the counter by half of N. The resultant value is the new N which is again used for...

HackerRank ā€˜Birthday Chocolateā€™ Solution

H

Short Problem Definition: The member states of the UN are planning to send 2 people to the moon. They want them to be from different countries. You will be given a list of pairs of astronaut IDā€™s. Each pair is made of astronauts from the same country. Determine how many pairs of astronauts from different countries they can choose from. Link Birthday Chocolate Complexity: time complexity is O(N)...

Archives

Categories