Home Tags Posts tagged with "Hackerrank"
Tag:

Hackerrank

  • Strings

    [Hackerrank] – Super Reduced Strings

    by nikoo28
    3 minutes read

    Let us try to understand this problem statement first. We have some strings that needs to be super reduced in size. The string consists of english alphabets from a to z, and they can be duplicated at some places. If we see two adjacent characters that are same, they can be eliminated. Following this pattern we have to return a super compressed/reduced string. Let us look at some sample test cases: Input: aabcccddOutput: “bc”Explanation:aabcccdd -> bcccdd -> bcdd -> bc(we eliminate two same adjacent characters at each step) Input: abbaOutput:…

    2 FacebookTwitterLinkedinWhatsappEmail
  • Misc

    [Hackerrank] – Number Line Jumps Solution

    by nikoo28
    4 minutes read

    Let us try to understand this problem statement first. We are in charge of a fancy circus and 2 kangaroos have to jump on a number line. The interesting part is that both the kangaroos have a different start position, and different jump distances. It is a little tricky to understand, the problems asks to calculate the number line jumps such that both the kangaroos are at the same position. We will try to simplify this using some diagrams, and see how the kangaroos actually jump. In the given test…

    1 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Equal Solution

    by nikoo28
    6 minutes read

    Let us try to understand this problem statement first. It is actually very verbose. We will try to simplify it as much as possible. Christy wants to give chocolates to her colleagues, and at the same time tries to ensure that everyone has equal chocolates at the end. To achieve this she either gives 1,2, or 5 chocolates to everyone except any one individual. Every-time she does this, it is counted as 1 operation. We need to make sure that Christy can achieve this task in the minimum number of…

    2 FacebookTwitterLinkedinWhatsappEmail
  • Question: Given a two strings, find the minimum number of characters that must be deleted to make them anagrams. Input: str1 = “a b c”, str2 = “a m n o p”Output: 6 Let us try to understand this problem statement and its test case first. We have two strings of english alphabet which may or may not have the same length. Anagrams are two words with same characters and frequencies. It is not necessary that the order of the characters is same. We have to determine, how many total…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: Given a string, count the number of times the letter ‘a’ is repeated. Input: str = “abcac”, n= 10 Output: 4 Let us try to understand this problem statement and its test case first. You have a string of lowercase English letters, that is repeated infinitely many times. Along with it, you also have a number ‘n’. You need to find out how many times the letter a appears in the first n characters of this infinite string. Let us look at a sample test case. Upon looking at…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Queue using two stacks

    by nikoo28
    5 minutes read

    A queue is a linear data structure which maintains the order in which the elements appear. You need to implement a queue, using two stacks such that it behaves in the same way. If you are unfamiliar with the queue data structure and the stack data structure, it would be a good idea to learn them before approaching this problem. Problem Statement: The basic crux of the problem is that you are to implement a queue and its operations using stacks. It may seem unnecessary in the beginning, as a…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: Given a string, Sherlock considers it valid if all the characters in the string occur the same number of time. However, a string is also valid if the frequencies are same after removing any one character. Example 1:Input: str = “aabbcd”Output: NO Example 2:Input: str = “abcc”Output: YES Problem Statement: Let us try to simplify the problem statement first. Sherlock needs to verify if a given string is valid. A string is valid under 2 conditions: All characters of the string appear the same number of times. If you…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Strings

    [Hackerrank] – Two Strings Solution

    by nikoo28
    3 minutes read

    Question: Given two strings, determine if they share a common sub-string. Input: “a” and “art” Output: YES Problem Statement Let me try to simplify this problem statement first. You are given two strings, and you need to find out if they share a common sub-string or not. If you can find a common sub-string, output “YES”, else output “NO”. Note that you don’t have to find out what is the common sub-string. Another important aspect of this problem is that the sub-string can be as small as 1 character. A…

    0 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More