• Sparse Arrays[HackerRank Solution]

    Sparse Arrays[HackerRank Solution] Problem: There is a collection of N strings ( There can be multiple occurences of a particular string ). Each string’s length is no more than 20 characters. There are also Q queries. For each query, you are given a string, and you need to find out how many times this string occurs in the…

  • Sherlock and Array[HackerRank Solution]

    Sherlock and Array[HackerRank Solution] Problem: 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…

  • Chocolate Feast[HackerRank Solution]

    Chocolate Feast[HackerRank Solution] Problem: Little Bobby loves chocolate, and he frequently goes to his favorite  store, Penny Auntie, with  dollars to buy chocolates. Each chocolate has a flat cost of  dollars, and the store has a promotion where they allow you to trade in  chocolate wrappers in exchange for  free piece of chocolate. For example, if  and Bobby has  dollars that he…

  • The Maximum Subarray[HackerRank Solution]

    The Maximum Subarray[HackerRank Solution] Dynamic Programming Problem: Given an array of N elements, find the maximum possible sum among all nonempty subarrays. all nonempty subsequences. We define a subarray as a contiguous subsequence. Note that empty subarrays/subsequences should not be considered. Input Format The first line of input contains a single integer T denoting the number of test cases. The first…

  • Big Sorting[HackerRank Solution]

    Big Sorting[HackerRank Solution] Problem: Consider an array of numeric strings, , where each string is a positive number with anywhere from  to  digits. Sort the array’s elements in non-decreasing (i.e., ascending) order of their real-world integer values and print each element of the sorted array on a new line. Input Format The first line contains an integer, , denoting the number…

  • Monk and Philosopher’s Stone[Hackerearth Solution]

    Monk and Philosopher’s Stone[Hackerearth Solution] PROBLEM: Harry Potter wants to get the Philosopher’s stone to protect it from Snape. Monk being the guard of Philosopher’s Stone is very greedy and has a special bag, into which he can add one gold coin at a time or can remove the last gold coin he added. Monk…

  • Count Substrings[GeeksforGeeks solution]

    Count Substrings[GeeksforGeeks solution] Question: Given a binary string, count number of substrings that start and end with 1. For example, if the input string is “00100101”, then there are three substrings “1001”, “100101” and “101”. Input: The first line contains T denoting the number of testcases. Then follows description of testcases. Each case contains a string…

  • Find Merge Point of Two Lists [hackerRank Solution]

    Find Merge Point of Two Lists [hackerRank Solution] Question: Given pointers to the head nodes of  linked lists that merge together at some point, find the Node where the two lists merge. It is guaranteed that the two head Nodes will be different, and neither will be NULL. In the diagram below, the two lists converge…

  • Delete duplicate-value nodes from a sorted linked list[HackerRank solution]

    Delete duplicate-value nodes from a sorted linked list[HackerRank solution] Question: You’re given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer…

  • Get Node Value [HackerRank solution]

    Get Node Value [HackerRank solution] You’re given the pointer to the head node of a linked list and a specific position. Counting backwards from the tail node of the linked list, get the value of the node at the given position. A position of 0 corresponds to the tail, 1 corresponds to the node before…