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 âAlternating Charactersâ Solution

Short Problem Definition: Shashank likes strings in which consecutive characters are different. For example, he likes ABABA, while he doesnât like ABAA. Given a string containing characters A and B only, he wants to change it into a string he likes. To do this, he is allowed to delete the characters in the string. Your task is to find the minimum number of required deletions. Link...

## HackerRank âAnagramâ Solution

Short Problem Definition:

Sid is obsessed with reading short stories. Being a CS student, he is doing some interesting frequency analysis with the books. He chooses strings S1 and S2 in such a way that |len(S1)âlen(S2)|â¤1

Link

Anagram

Complexity:

time complexity is O(N)

space complexity is O(N)

Execution:

Compare the frequency counts of the two parts.

Solution:

## HackerRank âAngryProfessorâ Solution

Short Problem Definition: The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are less than K students present after the class starts. Given the arrival time of each student, your task is to find out if the class gets cancelled or not. Link Angry Professor Complexity: time...

## HackerRank âApple and Orangeâ Solution

Short Problem Definition: Samâs house has an apple tree and an orange tree that yield an abundance of fruit. In the diagram below, the red region denotes his house, where s is the start point, and i is the endpoint. The apple tree is to the left of his house, and the orange tree is to its right. You can assume the trees are located on a single point, where the apple tree is at point a, and the...

## HackerRank âBalanced Parenthesesâ Solution

Short Problem Definition: Given a sequence consisting of parentheses, determine whether the expression is balanced. Link Balanced Parentheses Complexity: time complexity is O(N) space complexity is O(N) Execution: Equivalent to Codility Brackets. Solution: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 def isValidPair(left...

## HackerRank âBetween Two Setsâ Solution

Short Problem Definition: You will be given two arrays of integers and asked to determine all integers that satisfy the following two conditions: The elements of the first array are all factors of the integer being considered The integer being considered is a factor of all elements of the second array Link Between Two Sets Complexity: time complexity is O(A* (N+M)) space complexity is O(1)...

## HackerRank âBigger is Greaterâ Solution

Short Problem Definition: Given a word w, rearrange the letters of w to construct another word in such a way that is lexicographically greater than w. In case of multiple possible answers, find the lexicographically smallest one among them. Link Bigger is Greater Complexity: time complexity is O(N) space complexity is O(N) Execution: This task challenges us to find the next...