Hash Tables: Ransom Note

Harold is a kidnapper who wrote a ransom note, but now he is worried it will be traced back to him through his handwriting. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use only whole words available in the magazine. He cannot use substrings or conca

View Solution →

Two Strings

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 a. 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 com

View Solution →

Sherlock and Anagrams

Two strings are anagrams of each other if the letters of one string can be rearranged to form the other string. Given a string, find the number of pairs of substrings of the string that are anagrams of each other. For example s = mom , the list of all anagrammatic pairs is [m,m], [mo, om] at positions [ [1], [2], [0,1], [1,2] ] respectively . Function Description Complete the function she

View Solution →

Count Triplets

You are given an array and you need to find number of tripets of indices (i, j, k) such that the elements at those indices are in geometric progression for a given common ratio r and i < j < k . Function Description Complete the countTriplets function in the editor below. It should return the number of triplets forming a geometric progression for a given as an integer. countTriplets h

View Solution →

Frequency Queries

You are given q queries. Each query is of the form two integers described below: - 1 x: Insert x in your data structure. - 2 y: Delete one occurence of y from your data structure, if present. - 3 z: Check if any integer is present whose frequency is exactly z . If yes, print 1 else 0. The queries are given in the form of a 2-D array querries of size q where queries[i][0] contains the operati

View Solution →