CategoryCoding Challenge

HackerRank ‘Caesar Cipher’ Solution


Short Problem Definition: Julius Caesar protected his confidential information from his enemies by encrypting it. Caesar rotated every alphabet in the string by a fixed number K. This made the string unreadable by the enemy. You are given a string S and the number K. Encrypt the string and print the encrypted string. Link Caesar Cipher Complexity: time complexity is O(?) space complexity is O(?)...

HackerRank ‘CamelCase’ Solution


Short Problem Definition: Alice wrote a sequence of words in CamelCase as a string of letters, , having the following properties: It is a concatenation of one or more words consisting of English letters. All letters in the first word are lowercase. For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase...

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

HackerRank ‘Absolute Permutation’ Solution


Short Problem Definition: We define P to be a permutation of the first n natural numbers in the range [1,n]. Let pos[i] denote the value at position i in permutation P using 1-based indexing. P is considered to be an absolute permutation if |pos[i]-i| = K holds true for every i.  Link Absolute Permutation Complexity: time complexity is O(N) space complexity is O(N) Execution: The time complexity...

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 ‘Almost Sorted’ Solution


Short Problem Definition: Given an array of integers, determine whether the array can be sorted in ascending order using only one of the following operations one time. Swap two elements. Reverse one sub-segment. Determine whether one, both or neither of the operations will complete the task. If both work, choose swap. For instance, given an array [2, 3, 5, 4] either swap the 4 and 5; or reverse...

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 ‘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
time complexity is O(N)
space complexity is O(N)
Compare the frequency counts of the two parts.