Coding Interview Questions
- 0of 0 votes
AnswersPrint a 2-dimensional array in spiral way(handle border cases)
- Hinax August 28, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 0of 0 votes
AnswersConsider a number 123 , it is ordered since 1<2<3 . Now considering that , generate a permutation of all the possible passwords giving only the ordered sequence.
- Anonymous August 24, 2010| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersSuppose a start date is given to be 1 Jan 2000. take the user input as month day and year. Now, the input should be in the form month:03 day:11 year:2010. Now you have to calculate the amount of weeks between the date given and the 01.01.2000 assumed that each year you have 12 months. There is no leap year, and there are 30 days in a month. Now you have to take that week and display the listing of all the days in the week.
- Anonymous August 24, 2010| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersWrite a code to implement the Sodoku problem.
- Neetu August 12, 2010
Lets say you have a matrix of 9*9 and i can have valued from 1 to 9.
the rules are as below:
1. all the 3*3 matrix shouldn't have any duplicate number.
2. all the rows and columns can't have duplicate numebers.
3. all the diagonal elements in the 9*9 matrix can't have duplicate number.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Coding - 0of 0 votes
AnswersWrite a program to return distinct numbers from a given list?
- Jig August 10, 2010| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Coding - 1of 1 vote
Answersmemset is sometimes used to initialize data in a constructor like the example below. What is the benefit of initializing this way? Does it work in this example? Does it work in general ? Is it a good idea in general?
- Anonymous July 31, 2010
class A {
public:
A();
private:
int a;
float f;
char str[35];
long *lp;
};
A::A()
{
memset(this, 0, sizeof(*this));
}| Report Duplicate | Flag | PURGE
Interactive Brokers C Coding - 0of 0 votes
AnswersFibonacci Numbers: A number is said to be Fibonacci number if it follows the fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not necessarily start with 1, as with the normal fibonacci series. So, in this new definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and so is 252550(25,25,50).
- lego.mk July 31, 2010
So, given any two numbers as input, print out all the Fibonacci Numbers within that range..| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Coding - 0of 0 votes
AnswersPalindrome Date: A date is said to be a palindrome when it is expressed in MMDDYYYY format, it reads the same both ways. Given 2 years as input(ex: 2000, 2010), print out all the dates which are palindrome dates.
- lego.mk July 31, 2010| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Coding - 0of 0 votes
AnswersWrite a program to merge the two sorted link list ?
- Ballu July 23, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 0of 0 votes
AnswersA specification for a very simple file system stored inside a flat file (FS). There is an associated index file (FI) which provides meta-data to the data inside the flat file (FS).
- NoGeek July 16, 2010
FS:- FS cannot be larger than 1 MB. The entire space in FS is divided into blocks of 128 bytes.
FI:- FI provides meta-data regarding what is stored in FS. Directories, sub-directories and files are supported. Files can be binary or text which is marked in the meta-data. The following is a detailed description of FI-
FI consists of a sequence of entries or records. Each record (R) is 48 bytes long. Each record has an index and is referred by its index. There can be a max 8192 Records if each file is exactly one block long. Therefore FI can be at most 8192 x 48 = ~384KB in size. The structure of each R is -
1 2 3 4 5
|-----------------|--|--|---|-------|
1 Name (32 bytes)
2 Attribs (2 bytes) Described below
3 Directory Entry (2 bytes) - what is the parent directory of this record
4 Size (4 bytes) File size, 0 for Directory
5 Blocks list (8 bytes)
Name The file/dir name can be at most 32 bytes long. Only ascii alpha-numeric characters are allowed. The only symbols allowed are - $ and . A string shorter than 32 characters is terminated with an ascii value of 0.
Attributes Only the relevant attributes are described here
1st bit if set is a File else Dir
3rd bit if set is a Text file else Binary
Dir Entry The index of the parents Record in FI. The root entry has this value as 0.
Size - The actual size of the file (not the block count), always 0 for directories
Blocks list - Lists which blocks in FS holds the contents of this record. 8 bytes allows for 4 block indices to be specified each of size 2 bytes. If a file is larger than 4 block sizes (i.e. larger than 512 bytes) then a chaining mechanism is used where the last 2 bytes of the block from FS is used to point to the next block in FS. Suppose if the file is of 8 block size, then the last 2 bytes of 4th block will point to 5th block and last 2 bytes of 5th block points to 6th block and so on.
Directories will not have any block entries.
The root directory always occupies R[0].
Problem
A] Write a class com.progress.test.FSReader which has a static read method and takes as its only argument a file path similar to \files\abc.txt and returns a String of its contents. If the path provided is not a file or not a text file null must be returned. No exceptions must be thrown.
Signature -> String com.ma.test.FSReader.read(String path)
For test purposes, you can use file path \ma\ProblemStatement.txt which returns present file contents.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 0of 0 votes
AnswersDemonstrate memory leak.
- NoGeek July 16, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 0of 0 votes
AnswersGiven a root and a node of a binary tree, write a function which finds all the nodes which are a 'k' distance from the given nodes. (distance can be upwards and downwards)
- Loony June 30, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding Trees and Graphs - 0of 0 votes
AnswersWrite a URL shortner (like tinyurl) . Take a URL as input & return a shortened URL. If you use any kind of storage or persistence, please use the appropriate api's of the language. Another requirement is that we want to make our URLs as different as possible, so that successive calls return very different URIs
- dynamic June 29, 2010
This is to ensure that small typo errors do not lead to users getting to a valid URL, but rather throwing up an error page.| Report Duplicate | Flag | PURGE
Flipkart Software Engineer / Developer Coding - 0of 0 votes
Answersinput is n, find the no. of 0's at the end of n! [factorial of n]
- someone June 28, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 0of 0 votes
Answershow to perform permutation...
- naganathan June 25, 2010| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersHow to merge two trees with less time complexity.
- naganathan.cit June 17, 2010| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersWrite a program to print out the power set of a set.
- CS June 09, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 0 votes
AnswersWrite a function to validate a SuDoKu board.
- CS June 09, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 1of 1 vote
AnswersRound-3-Qn-2)
- Arang May 26, 2010
- You are given two 4 digits prime numbers N1 and N2,
- You can change only one digit of N1 at a time.
- Resultant of changing a digit of N1 should also be a prime number.
How many number of digit changes (minimum) are required to convert N1 to N2?
Example:
Assume (8785, 8787, 8887, 9887, 9897) are prime numbers.
Lets say N1=8785 and N2 = 9897 then
change-1: 8785 => 8787
change-2: 8787 => 8887
change-3: 8887 => 9887
change-4: 9887 => 9897
So 4 digit changes are require to convert N1 to N2.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersRound-2-Qn-2) Implement a data structure such that it provides push(), pop() and GetMax() operations and running time of all operations should be constant O(1).
- Arang May 26, 2010
Note: GetMax need not remove the max from the data structure.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersRound-1-Qn-2) Given a binary tree, we need to create a matrix.
Example:
- Arang May 26, 2010A / \ B C / \ / \ D E F G |A|B|C|D|E|F|G| ------------------ A| B|1 (B is child of A) C|1 (C is child of A) D|1 1 (D is child of A & B) E|1 1 (E is child of A & B) F|1 1 (F is child of A & C) G|1 1 (G is child of A & C)
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersRound-1-Qn-1) Find vertical sum of given binary tree.
Example:1 / \ 2 3 / \ / \ 4 5 6 7
The tree has 5 vertical lines
Vertical-1: nodes-4 => vertical sum is 4 Vertical-2: nodes-2 => vertical sum is 2 Vertical-3: nodes-1,5,6 => vertical sum is 1+5+6 = 12 Vertical-4: nodes-3 => vertical sum is 3 Vertical-5: nodes-7 => vertical sum is 7
We need to output: 4 2 12 3 7
- Arang May 26, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersWritten-Qn-3) Given a binary tree and a number N, check is there any path exists in the tree such sum of the nodes in the path equals to N.
bool isPathExists(Node *root, int N)
Note: We can assume that node contains only positive integers
Example:1 / \ 2 3 / \ / \ 4 5 6 7
if N = 8, return TRUE
- Arang May 26, 2010
if N = 9, return FALSE| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersWritten-Qn-2) Write complete working code (only the function) to traverse a binary tree in ZigZag order
void printTree(Node *root)
Example:1 / \ 2 3 / \ / \ 4 5 6 7
O/P: 1 3 2 4 5 6 7
- Arang May 26, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersWritten-Qn-1) Write complete working code (only the function) to check whether the given char sequence is valid.
- Arang May 26, 2010
bool isValid(char *str)
Example:
I/P: ()()().... O/P: Valid.
I/P: ())()(.... O/P: Invalid.
* We can assume that the input will have only squence of '(' and ')' chars.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes
AnswersGiven a very very long linked list with 'n' nodes.
- Abhinav May 19, 2010
Also given a positive integer 't'>1.
Delete every 't'th node. In the resultant linked list, again delete 't'th node. Repeat this till only t-1 nodes remains.
Find the node.
Eg:
Linked list : 10->20->30->40->50->60->70
n = 7
t = 3
Phase 1:
10->20->40->50->70
Phase-2:
10->20->50->70
Phase-3:
10->20->70
Phase-4:
10->20
Simple solution with many traversals is obvious.
Is there a solution with one traversal or O(n)?
b) Similar for circular linked list.
Keep deleting 't'th node till 1 node remains.
Note here not till 't-1' nodes but till 1 node remains.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm C Coding - 0of 0 votes
AnswersWrite code to return the numbers of almost prime numbers in a given range. Remember an almost prime number is a number one degree off prime - basically a non-prime number divided by a prime number that equals a prime number.
- biggied88 May 18, 2010
example: 4/2 = 2 or 26/13 = 2 both numbers are almost prime numbers
given in question: the first 25 prime numbers are - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.| Report Duplicate | Flag | PURGE
Denmin Group Software Engineer / Developer Coding - 0of 0 votes
Answerwrite code to return the shape with the largest area in a collection of shapes. the shape can be a square, circle ,or rectangle. The collection can hold any type of these shapes
- biggied88 May 18, 2010| Report Duplicate | Flag | PURGE
Denmin Group Software Engineer / Developer Coding