Featured Article

Absolute distinct count in a sorted array

Given a sorted array of integers, return the number of distinct absolute values among the elements of the array. The input can contain duplicates values. Input: [-3, -2, 0, 3, 4, 5] Output: 5 There are 5 distinct absolute values among the elements of this array, i.e. 0, 2, 3, 4 and 5) Input: [-1,… Read More »

Times Internet Interview Experience | Set 2 (Experienced)

Times Internet Round 1: Discussion about projects and work Search in a rotated sorted arrayhttp://www.geeksforgeeks.org/find-minimum-element-in-a-sorted-and-rotated-array/ Implement stack with find minimum in O(1) http://www.geeksforgeeks.org/design-and-implement-special-stack-data-structure/ Round 2: Spiral printing of a matrixhttp://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/ LCA of Binary Treehttp://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/ Boggle http://www.geeksforgeeks.org/boggle-find-possible-words-board-characters/ DFS implementation Round 3: It was a machine coding round. I was asked to hit an API and get… 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 »

Combinatorial Game Theory | Set 2 (Game of Nim)

We strongly recommend to refer below article as a prerequisite of this. Combinatorial Game Theory | Set 1 (Introduction) In this post, Game of Nim is discussed. The Game of Nim is described by the following rules- “ Given a number of piles in which each pile contains some numbers of stones/coins. In each turn,… Read More »

Branch and Bound | Set 3 (8 puzzle Problem)

We have introduced Branch and Bound and discussed 0/1 Knapsack problem in below posts. Branch and Bound | Set 1 (Introduction with 0/1 Knapsack) Branch and Bound | Set 2 (Implementation of 0/1 Knapsack) In this puzzle solution of 8 puzzle problem is discussed. Given a 3×3 board with 8 tiles (every tile has one… Read More »

Combinatorial Game Theory | Set 1 (Introduction)

Combinatorial games are two-person games with perfect information and no chance moves (no randomization like coin toss is involved that can effect the game). These games have a win-or-lose outcome and determined by a set of positions, including an initial position, and the player whose turn it is to move. Play moves from one position… Read More »

Comparable vs Comparator in Java

Java provides two interfaces to sort objects using data members of the class: Comparable Comparator Using Comparable Interface A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface to compare its instances. Consider a Movie class that has members like, rating, name, year. Suppose we wish… Read More »

Print Binary Tree in 2-Dimensions

Given a Binary Tree, print it in two dimension. Examples: Input : Pointer to root of below tree 1 / \ 2 3 / \ / \ 4 5 6 7 Output : 7 3 6 1 5 2 4 We strongly recommend you to minimize your browser and try this yourself first. If we… Read More »