Explain ACID properties?

ACID stands for Atomicity Consistency Isolation Durablity Atomicity Modification on the data in the database either fail or succeed. The beginning of such a modification starts with a transaction and ends when a transaction finishes (either by a commit or a rollback). A software crash entails an implicit rollback. Consistency Only valid data (valid according Read More →

Adobe Interview – Set 2

I am from MNIT Jaipur. I recently got interviewed in our campus placement for Adobe, following is my interview experience. Round 1 They started with something I did not even think of, Images fundamentals. Making images blurry, making them shaggy. Operating on images in parallel. Hardware engines support for parallelism. Some other fundamentals Adobe people were Read More →

Find first non repeating character in a string

You are given a string, find its first non-repeating character? Algorithm: 1) Scan the string from left to right and construct the count array. 2) Again, scan the string from left to right and check for count of each character, if you find an element who’s count is 1, return it. Time complexity: O(N)

Find local minima in an array

You are given an array Arr[1 .. n] with the special property that Arr[1] ≥ Arr[2] and Arr[n − 1] ≤ Arr[n]. We say that an element Arr[x] is a local minimum if it is less than or equal to both its neighbors. Derive an algorithm in O(log n) For example in the array 9,6,2,14,5,7,4 Read More →

Amazon Interview – Set 3

I appeared for Amazon campus interview on 30th July 2013. I am from MNIT Jaipur. I would like to contribute for CrazyforCode by sharing my experience. Round 1 Q1. Tell me about yourself? Q2. DBMS project discussion. Q3. How to merge k sorted arrays of n length and discussion on its complexity? Q4. A question Read More →

Squares on a chess board?

Chess board squares puzzle

Problem: How many squares are on a chess board? If you thought the answer is 64, think again! How about all the squares that are formed by combining smaller squares on the chess board (2×2, 3×3, 4×4 squares and so on)? A 1×1 square can be placed on the chess board in 8 horizontal and 8 Read More →

Difference between DDL, DML and DCL commands?

Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples: CREATE – to create objects in the database or tables ALTER – alters the structure of the database or tables DROP – delete objects from the database TRUNCATE – remove all records from a table, including all spaces allocated Read More →

Binary Tree diff of sum of nodes at odd and sum of nodes at even

difference of sum of nodes at even and odd levels

Given a Binary Tree, write a function which calculates the difference between the sum of node values at odd levels and sum of node values at even levels. Consider the root node is at height 1. The solution is short and uses recursion. The idea is that you negate all levels under the current one Read More →

Even numbers at even index and Odd numbers at odd index

You are given an array of positive numbers. You have to rearrange array such that even numbers at even position and odd numbers at odd positions. If suppose odd numbers exceeds the even numbers or vice-versa than keep them untouched. Do this in one pass and without using any extra memory. input : {2 5 7 Read More →

The Fox and The Duck Puzzle

duck and fox puzzle

Problem: This is the classical puzzle asked in microsoft interview A duck, pursued by a fox, escapes to the center of a perfectly circular pond. The fox cannot swim, and the duck cannot take flight from the water. The fox is four times faster than the duck. Assuming the fox and duck pursue optimum strategies, Read More →

Print all root to leaf paths in a tree

Binary Tree

Given a binary tree,Print all root to leaf paths in it. root to leaf paths in above tree. [1 2 4] [1 3 5] [1 3 6] We start with the root and while traversing the tree we keep storing node data in array.We print the array when we reach a leaf node. Time Complexity Read More →

Search in a row wise and column wise sorted matrix

You are given an 2D array of MxN which is row and column wise sorted. What is the efficient way to search for an element? Steps: 1) Start from top right element 2) for loop compare this element e with x a) if they are equal then return its position b) e < x then Read More →