In fact, the STL's map class allows you to store data by any type of key instead of simply by a numerical key, the way you must access an array or vector. So instead of having to compute a hash function and then access an array, you can just let the map class do it… Continue reading STL – Map

# Category: C++

some notes about C++

# Sieve of Eratosthenes Algorithm

if we want to find prime numbers up to some predefined integer n, there are some steps to find the prime numbers. (trial division) find primes (int arr[]) define empty list for from i = 2 to i = n if isPrime (i) if true (add i to list) Implementation (Trial division) in c++ #include <iostream>… Continue reading Sieve of Eratosthenes Algorithm

# Hacker Rank “Sherlock and Anagrams”

Given a string , find the number of "unordered anagrammatic pairs" of substrings. Input Format First line contains , the number of testcases. Each testcase consists of string in one line. Output Format For each testcase, print the required answer in one line. Sample Input#00 2 abba abcd Sample Output#00 4 0 Sample Input#01… Continue reading Hacker Rank “Sherlock and Anagrams”

# Stack and Queue

Stacks are a type of container designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container. Main Stack Operations: push (object): inserts an element. pop (): removes and returns the last inserted element. top(): returns the last element without removing it. size(): returns… Continue reading Stack and Queue

# Vectors

Arrays in C++ have a number of drawbacks that make them inconvenient to use: The size of the array must be a fixed constant. Passing an array as a parameter to a function is inconvenient; you must also pass the size of the array as a separate parameter. There is no way to conveniently insert… Continue reading Vectors

# Binary Search

the simple searching algorithm for searching an element in array is Linear Search and the time complexity for linear search is o(n). Binary search is one of the fundamental algorithms in computer science. and an effective algorithm as compared to linear search . Binary search algorithm in C++ relies on a divide and conquer strategy to find a… Continue reading Binary Search

# HackerRank “Super Reduce String”

Shil has a string, , consisting of lowercase English letters. In one operation, he can delete any pair of adjacent letters with same value. For example, string "" would become either "" or "" after operation. Shil wants to reduce as much as possible. To do this, he will repeat the above operation as many… Continue reading HackerRank “Super Reduce String”