Balanced Brackets –  HackerRank Problem Solution

Question: A bracket is considered to be any one of the following characters: (, ), {, }, [, or ]. Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and (). A matching pair of brackets is not balanced if the set of brackets it encloses … Continue reading Balanced Brackets –  HackerRank Problem Solution

Append and Delete –  HackerRank Problem Solution

Question: You have a string of lowercase English alphabetic letters. You can perform two types of operations on the string: 1.       Append a lowercase English alphabetic letter to the end of the string. 2.       Delete the last character in the string. Performing this operation on an empty string results in an empty string. Given an integer,k , and two strings, s and t, determine whether or not you can convert  to  by performing exactly  k … Continue reading Append and Delete –  HackerRank Problem Solution

Binary Numbers – HackerRank Problem solution

Question: Given a base- 10 integer, n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1’s in n Input: Output: Explanation Sample Case 1:The binary representation of 5 is 101, so the maximum number of consecutive 1’s is 1. Here is original problem from HackerRank Answer: Continue reading Binary Numbers – HackerRank Problem solution

Migratory Birds – HackerRank Problem Solution

Question: You have been asked to help study the population of birds migrating across the continent. Each type of bird you are interested in will be identified by an integer value. Each time a particular kind of bird is spotted, its id number will be added to your array of sightings. You would like to be able to find out which type of bird is … Continue reading Migratory Birds – HackerRank Problem Solution

Ice Cream Parlor – HackerRank Problem Solution

Question Sunny and Johnny like to pool their money and go to the ice cream parlor. Johnny never buys the same flavor that Sunny does. The only other rule they have is that they spend all of their money. Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they have. For example, they … Continue reading Ice Cream Parlor – HackerRank Problem Solution

Counting Valleys – HackerRank Problem solution

Question: Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly n steps. For every step he took, he noted if it was an uphill, U, or a downhill, D step. Gary’s hikes start and end at sea level and each step up or down represents a 1 unit change in altitude. We define the following terms: A mountain is … Continue reading Counting Valleys – HackerRank Problem solution

Staircase – HackerRank Problem solution

Question: Consider a staircase of size n=4: Observe that its base and height are both equal to n , and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces. Write a program that prints a staircase of size n  input: Output: Here is actual problem HackerRank. Answer: Solution Logic Take variable which stores value of white space, initialize it with array … Continue reading Staircase – HackerRank Problem solution

Sock Merchant – HackerRank Problem Solution

Question: John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. For example, there are n=7  socks  with colors  ar = [1,2,1,2,1,3,2]. There is one pair of color 1 and one of color 2 . There … Continue reading Sock Merchant – HackerRank Problem Solution

Alternating Characters – HackerRank Problem Solution

Question: 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 can delete zero or more characters in the string. Your task is to find the minimum number of required deletions. For example, given the string s=AABAAB, remove an A at positions 0 and 3  … Continue reading Alternating Characters – HackerRank Problem Solution