Short Problem Definition: Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria: Its length is at least 6. It contains at least one digit. It contains at least one...

## HackerRank âSuper Reduced Stringâ Solution

Short Problem Definition: Steve has a string of lowercase characters in range ascii[âaâ..âzâ]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one operation. Steveâs task is to...

## HackerRank âTaum and Bâdayâ Solution

Short Problem Definition: Taum is planning to celebrate the birthday of his friend Diksha. There are two types of gifts that Diksha wants from Taum: one is black and the other is white. To make her happy, Taum has to buy B number of black gifts and W number of white gifts. Link Taum and Bâday Complexity: time complexity is O(1) space complexity is O(1) Execution: The cost for each present is...

## HackerRank âSherlock and Arrayâ Solution

Short Problem Definition: Watson gives Sherlock an array A of length N. Then he asks him to determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its right. If there are no elements to the left/right, then the sum is considered to be zero.Formally, find an i, such that, A1+A2âŚAi-1 =Ai+1+Ai+2âŚAN Link Sherlock and...

## HackerRank âSherlock and GCDâ Solution

Short Problem Definition: Sherlock is stuck while solving a problem: Given an array A={a1,a2,..aN}, he wants to know if there exists a subset, B={ai1,ai2,âŚaik} where 1â¤i1<i2<âŚ<ikâ¤NâŚ Link Sherlock and GCD Complexity: time complexity is O(N); space complexity is O(1) Execution: A subset has no common divisor if the GCD equals 1. There is an interesting fact that leads to my solution: If...

## HackerRank âSherlock and Pairsâ Solution

Short Problem Definition: Sherlock is given an array of N integers A0, A1 âŚ AN-1 by Watson. Now Watson asks Sherlock how many different pairs of indices i and j exist such that i is not equal to j but Ai is equal to Aj. That is, Sherlock has to count total number of pairs of indices (i, j) where Ai = Aj AND i â j. Link Sherlock and Pairs Complexity: time complexity is O(n) space complexity is...

## HackerRank âSherlock and Squaresâ Solution

Short Problem Definition: Watson gives two integers A & B to Sherlock and asks if he can count the number of square integers between A and B (both inclusive). A square integer is an integer which is the square of any integer. For example, 1, 4, 9, 16 are some of the square integers as they are squares of 1, 2, 3, 4 respectively. Link Sherlock and Squares Complexity: time complexity is O(sqrt(N));...

## HackerRank âSherlock and The Beastâ Solution

Short Problem Definition: Sherlock Holmes suspects his archenemy, Professor Moriarty, is once again plotting something diabolical. Sherlockâs companion, Dr. Watson, suggests Moriarty may be responsible for MI6âs recent issues with their supercomputer, The Beast. Shortly after resolving to investigate, Sherlock receives a note from Moriarty boasting about infecting The Beastwith a virus; however...

## HackerRank âSherlock and The Valid Stringâ Solution

Short Problem Definition: Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just 1 character at 1 index in the string, and the remaining characters will occur the same number of times. Given a string , determine if it is valid. If so, return YES, otherwise...

## HackerRank âSherlock and Valid Stringâ Solution

Short Problem Definition: Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just 1 character at 1 index in the string, and the remaining characters will occur the same number of times. Given a string , determine if it is valid. If so, return YES, otherwise...