Difficulty: Medium Asked in: Amazon, Google Understanding The Problem Problem Description There are N gas stations along a circular route, where the amount of gas at station i is arr[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i toContinue reading… Gas Station Problem

# Category: Algorithms

## Number of comparisons to find second minimum element in an Array

Given an array of numbers, we need to find the second min element with optimal number of comparisons. Let’s compare two elements (side by side) and get next set of min element list. Recursively, we end up with lowest numberContinue reading… Number of comparisons to find second minimum element in an Array

## Base64 Encoding and Decoding in C

Base64 is a method of encoding arbitrary data as plain ASCII text. It is one of the techniques employed by the MIME standard to send data other than plain text. Base64 encoding takes three bytes, each consisting of eight bits,Continue reading… Base64 Encoding and Decoding in C

## Memory efficient doubly linked list

Linux Journal has an article in the January 2005 issue that introduces a doubly linked list that is designed for memory efficiency. Typically elements in doubly linked list implementations consist of a pointer to the data, a pointer to theContinue reading… Memory efficient doubly linked list

## There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1].

Solve it without division operator and in O(n).

## You have 1000 integers. All are less than 1000 and greater or equal to 1. Among them, 999 are distinct and there is one that is found twice. How can you find the duplicate?

Extension to this questions is – if there are some billion numbers are there, and you have enough memory to fit all these numbers. What is the best of to do the same?

## if I had to find duplicates in book catalogs with entries with different titles but with the same content..

This is related to google print application. In other words, we have many books out of which some books titles were different but content same. We need to figure out such cases efficiently. How?

## Create a function, called findZeros(), that will compute the number of zeros in the decimal representation of n!

For example, 5! = 1.2.3.4.5= 120 has one zero and 10! = 1.2.3.4.5.6.7.8.9.10 = 3628800 and has two zeros. can anybody help? best of all answers comes here …

## Create a function, called powerSet(), that will output the power set of the input set.

The power set in Algebra theory is the set of all subsets of a set (no..bull-set!) If a set has N elements then the power set will have 2^N elements. So if a set is denoted by {a,b} with a,bContinue reading… Create a function, called powerSet(), that will output the power set of the input set.

## Typical Unix/Linux recursive search commands

The Typical one is – to find the files with some pattern recursively in a given directory. $ find path/to/dir -name “*.html” You can replace the “*.html” to your own filename pattern. Another one is, in addition to above IContinue reading… Typical Unix/Linux recursive search commands