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 âA Very Big Sumâ Solution

Short Problem Definition:

Calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.

Link

A Very Big Sum

Complexity:

time complexity is O(N)

space complexity is O(1)

Execution:

Just add all of this together. No magic.

Solution:

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

Link

Anagram

Complexity:

time complexity is O(N)

space complexity is O(N)

Execution:

Compare the frequency counts of the two parts.

Solution: