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 ‘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 ‘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 ‘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 ‘ACM ICPC Team’ Solution

Short Problem Definition: You are given a list of N people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-person team can know. And also find out how many teams can know that maximum number of topics. Link ACM ICPC Team Complexity: time complexity is O(N^3); space complexity is O(N) Execution: I...

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