Posts

Showing posts from July, 2019

Two Strings - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. Given two strings, determine if they share a common substring. A substring may be as small as one character. For example, the words "a", "and", "art" share the common substring  . The words "be" and "cat" do not share a substring. Function Description Complete the function  twoStrings  in the editor below. It should return a string, either  YES  or  NO  based on whether the strings share a common substring.

Circular Array Rotation - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. John Watson knows of an operation called a  right circular rotation  on an array of integers. One rotation operation moves the last array element to the first position and shifts all remaining elements right one. To test Sherlock's abilities, Watson provides Sherlock with an array of integers. Sherlock is to perform the rotation operation a number of times then determine the value of the element at a given position. For each array, perform a number of right circular rotations and return the value of the element at a given

Funny String - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. In this challenge, you will determine whether a string is  funny  or not. To determine whether a string is funny, create a copy of the string in reverse e.g.  . Iterating through each string, compare the absolute difference in the  ascii  values of the characters at positions 0 and 1, 1 and 2 and so on to the end. If the list of absolute differences is the same for both strings, they are funny. Determine whether a give string is funny. If it is, return  Funny , otherwise return  Not Funny . For example, given the string  , the ordinal values of the charcters are  .  and the ordinals are  . The

Making Anagrams - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example,  bacdc  and  dcbac  are anagrams, but  bacdc  and  dcbad  are not. Alice is taking a cryptography class and finding  anagrams  to be very useful. She decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of

Alternating Characters - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. You are given a string containing characters   and   only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string. Your task is to find the minimum number of required deletions. For example, given the string  , remove an   at positions   and   to make   in   deletions.

Gemstones - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. John has collected various rocks. Each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range  . There may be multiple occurrences of a mineral in a rock. A mineral is called a  gemstone  if it occurs at least once in each of the rocks in John's collection.

HackerRank in a String! - HackerRank Solution.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. We say that a string contains the word  hackerrank  if a  subsequence  of its characters spell the word  hackerrank . For example, if string   it does contain  hackerrank , but   does not. In the second case, the second  r  is missing. If we reorder the first string as  , it no longer contains the subsequence due to ordering. More formally, let   be the respective indices of  h ,  a ,  c ,  k ,  e ,  r ,  r ,  a ,  n ,  k  in string  . If   is true, then   contains  hackerrank .