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 sherlockAndAnagrams in the editor below. It must return an integer that represents the number of anagra
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 has the following parameter(s): arr: an array of integers r: an integer, the common ratio
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 operation, and queries[i][1] contains the data element. For example, you are given array queries = [ (
View Solution →Say "Hello, World!" With C++
Objective This is a simple challenge to help you practice printing to stdout. You may also want to complete Solve Me First in C++ before attempting this challenge. We're starting out by printing the most famous computing phrase of all time! In the editor below, use either printf or cout to print the string Hello, World! to stdout. The more popular command form is cout. It has the following basic form: cout<<value_to_print<<value_to_print; Any number of values can be printed using o
View Solution →Input and Output C++
Objective In this challenge, we practice reading input from stdin and printing output to stdout. In C++, you can read a single whitespace-separated token of input using cin, and print output to stdout using cout. For example, let's say we declare the following variables: string s; int n; and we want to use cin to read the input "High 5" from stdin. We can do this with the following code: cin >> s >> n; This reads the first word ("High") from stdin and saves it as string s , then
View Solution →