Featured Article

Cyclic Redundancy Check and Modulo-2 Division

CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in communication channel. CRC uses Generator Polynomial which is available on both sender and receiver side. An example generator polynomial is of the form like x3 + x + 1. This generator polynomial represents key 1011. Another example is x2 + 1 that… Read More »

Featured Article

Find maximum product of a triplet in array

Given an integer array, find a maximum product of a triplet in array. Examples: Input: [10, 3, 5, 6, 20] Output: 1200 Multiplication of 10, 6 and 20 Input: [-10, -3, -5, -6, -20] Output: -90 Input: [1, -4, 3, -6, 7, 0] Output: 168 We strongly recommend that you click here and practice it,… Read More »

Featured Article

Myth about the file name and class name in Java

The first lecture note given during java class is “In java file name and class name should be the same”. When the above law is violated a compiler error message will appear as below Output: javac Trial.java Trial.java:9: error: class Geeks is public, should be declared in a file named Geeks.java public class Geeks ^… Read More »

Featured Article

Count pairs formed by distinct element sub-arrays

Given an array, count number of pairs that can be formed from all possible contiguous sub-arrays containing distinct numbers. The array contains positive numbers between 0 to n-1 where n is the size of the array. Examples: Input: [1, 4, 2, 4, 3, 2] Output: 8 The subarrays with distinct elements are [1, 4, 2],… Read More »

Featured Article

Cuckoo Hashing – Worst case O(1) Lookup!

Background : There are three basic operations that must be supported by a hash table (or a dictionary): Lookup(key): return true if key is there in the table, else false Insert(key): adds the item ‘key’ to the table if not already present Delete(key): removes ‘key’ from the table Collisions are very likely even if we… Read More »

Microsoft Interview experience | Set 92 (1.8 Yrs Experienced for IDC)

My resume was forwarded to Microsoft through a consultancy firm. I was called for a day long interview process at Microsoft IDC, Bangalore. Round 1 (1 hour+): Question 1: http://www.geeksforgeeks.org/median-of-stream-of-integers-running-integers/ I first gave the insertion sort algorithm, he told me to improve upon it. I was stuck for some time so he gave me another… Read More »

Generators in Python

Prerequisites: Yield Keyword and Iterators There are two terms involved when we discuss generators. Generator-Function : A generator-function is defined like a normal function, but whenever it needs to generate a value, it does so with the yield keyword rather than return. If the body of a def contains yield, the function automatically becomes a… Read More »

Iterators in Python

Iterator in python is any python type that can be used with a ‘for in loop’. Python lists, tuples, dicts and sets are all examples of inbuilt iterators. These types are iterators because they implement following methods. In fact, any object that wants to be an iterator must implement following methods. __iter__ method that is… Read More »

Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)

Prerequisite : Object Oriented Programming in Python | Set 1 (Class, Object and Members)   Data hiding In Python, we use double underscore (Or __) before the attributes name and those attributes will not be directly visible outside. Output : 2 7 Traceback (most recent call last): File “filename.py”, line 13, in print (myObject.__hiddenVariable) AttributeError:… Read More »

Permutation and Combination in Python

Python provide direct methods to find permutations and combinations of a sequence. These methods are present in itertools package. Permutation First import itertools package to implement permutations method in python. This method takes a list as an input and return an object list of tuples that contain all permutation in a list form. Output (1,… Read More »

Check if two trees are Mirror

Given two Binary Trees, write a function that returns true if two trees are mirror of each other, else false. For example, the function should return true for following input trees. We strongly recommend that you click here and practice it, before moving on to the solution. This problem is different from the problem discussed… Read More »