Coding Interview Questions
- 16of 18 votes
AnswersOutput top N positive integer in string comparison order. For example, let's say N=1000, then you need to output in string comparison order as below:
- John July 15, 2014 in United States
1, 10, 100, 1000, 101, 102, ... 109, 11, 110, ...| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 2 votes
AnswersHow to design a multi key hash map ( key count can be dynamic. if there are two keys , initiallly which can be used to find the value , keys can be increased to three as well ex: consider school structure. Intially , consider , student id is key , later , should be searchable even with key name , later with grade.
- gopi.komanduri July 05, 2014 in India| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays C# C++ Coding Data Structures Dynamic Programming Experience Hash Table Large Scale Computing Linked Lists Problem Solving Sorting Trees and Graphs - 1of 3 votes
AnswersDesign a telephone directory for large ppl (he gave example like design for India). fields will be , first name , last name , number . this should be searchable with first name , last name , number as welll.
- gopi.komanduri July 04, 2014 in India
later added more complexity like do the same for organisation where even it contains designations. so this should be searchable with designations.| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays C C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Dynamic Programming Hash Table Ideas Large Scale Computing Linked Lists Object Oriented Design Problem Solving Trees and Graphs - 0of 0 votes
AnswersIn Mathematics each number has one special number, which it supports, chosen as follows. It counts the number of ones in its own binary representation, and adds this count to itself to obtain the value of the number it supports. That is, if j(m) means the number of ones in the binary representation of m, then m supports m+j(m). For example, the number eight (1000 in binary) supports nine, whereas nine supports eleven.
- anonymous June 16, 2014 in India
However, in this way not all the numbers get supported; some are left without support, and we call these numbers bleak. For example since one supports two, two supports three and three supports five, there is no number less than four, which would support four, so four is bleak.
Your task is for a given number recognize if it is bleak or supported by some number.| Report Duplicate | Flag | PURGE
Sap Labs Software Engineer / Developer Coding - 0of 0 votes
AnswersWrite a method that takes a given string and replaces all occurrences of one string with another string, returning the number of replaces made. For instance given the string “Microsoft” if you were to replace all occurrences of “ic” with “MSFT” the result would be “MMSFTrosoft” with a return value of 1. As part of a final solution please provide unit tests done as well as any test cases ran. Please note that you may not use String.Replace or string::replace depending upon the language you use; you must write this functionality yourself.
- warunthambi June 10, 2014 in India for teamviewer| Report Duplicate | Flag | PURGE
Microsoft Developer Program Engineer Coding - 0of 0 votes
AnswersImplement a class that does string manipulation by overloading the following operators: <<, >>, = and ==. For example consider the following code:
- warunthambi June 10, 2014 in India for teamviewer
StrShift example;
example = “Microsoft”;
printf(“\”example << 2\” results in %s\n“, example << 2);
In the above code the output would be “ftMicroso” which shows the last two characters of the string “Microsoft” rotated to the left of the string. Please note that state is maintained so two calls of example << 1 would give the same end result as calling example << 2 once. Consideration will be given to correctness, design, code readability as well as any unit testing. As part of a final solution please submit test cases you used to verify correctness in addition to any unit tests done.| Report Duplicate | Flag | PURGE
Microsoft Developer Program Engineer Coding - 0of 0 votes
AnswersWrite a class that represents a minimal heap. The heap class should at a minimum support the following methods:
- warunthambi June 10, 2014 in India for teamviewer
- AllocTinyHeap() which should initialize the heap with a given amount of bytes
- DeleteTinyHeap() which frees all memory associated with the heap
- TinyAlloc() which allocates a given number of bytes on the heap if there is room
- TinyFree() which frees a specific location on the heap
You may define whatever parameters are necessary for the above methods as well as write any additional methods. Overall consideration will be given to correctness, design, code readability as well as any unit testing done. As part of a final solution please submit test cases you used to verify correctness in addition to any unit tests done.| Report Duplicate | Flag | PURGE
Microsoft Developer Program Engineer Coding - -2of 2 votes
AnswersThe boggle game - given a 2d array of characters
- FauxPas June 07, 2014 in United States| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm Coding Java - 1of 1 vote
AnswersEvaluate a given mathematical expression, taking into consideration the BODMAS rule. The expression contains no brackets.
- FauxPas June 07, 2014 in United States| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm Coding Java - 0of 0 votes
AnswersSerialize and deserialize a tree.
- FauxPas June 07, 2014 in United States
Given a tree - not necessarily a binary tree - the serialize method should create a string for the tree. The deserialize method should be able to reproduce the same tree using the string derived from the serialize method.
Basically, serialize() takes in a tree and returns a string, deserialize() takes in a string and returns the tree.| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm Coding Java Object Oriented Design - 0of 0 votes
AnswersGiven a binary tree, write a method to determine shortest distance between two nodes. A node does not have a pointer to its parent
- Serengeti June 03, 2014 in United States| Report Duplicate | Flag | PURGE
Spotify Software Engineer / Developer Coding - 0of 0 votes
AnswersGiven a binary tree, write a method to determine shortest distance between two two nodes. The node does not have a pointer to its parent
- Serengeti June 03, 2014 in United States| Report Duplicate | Flag | PURGE
Spotify Software Engineer / Developer Coding - 1of 1 vote
AnswersGiven a graph, write a method to check if it is bipartite
- Serengeti June 03, 2014 in United States| Report Duplicate | Flag | PURGE
Spotify Software Engineer / Developer Coding - 1of 1 vote
AnswersImplement thread-safe circular queue that has 2 methods Read & Write n bytes.
- Goooogle2014 May 29, 2014 in United States for Azure
The entire design and implementation was open for discussion.
Discussion went for locking, multi threading, boundary cases, all sets of issues related to multi threading..it was quite intense..| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding - 16of 18 votes
AnswersMachine Coding:
- ponmurugesh2012 May 20, 2014 in India
Design and code application similar to IPL website.
1. There are players who belong different teams [CSK, RCB,etc].
2. User can create their own team from the player set
3. When a match happens, there are possible outcome in each ball [one run, six, wicket, run-out, etc]
4. on each outcome, players involved will get points [eg: six = batsman 5 points, wicket = batsman minus 5 and bowler +5, etc]
5. Based on outcome, the user created team also should be able to calculate his points.
6. Solution should be working code, extensible and performance.| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Coding - 0of 0 votes
AnswersGiven a set of 21 tasks = {A, B,....Z} except I, O, U, X and Q. Each task requires 4 hours of processing. Except for tasks E, Y, P, R, W that require 8 hours of processing.
- foobar May 14, 2014 in United States
You have 3 machines to process these tasks = T1, T2, T3. T1 and T2 are available everyday for 8 hours. T3 is available only on Mon, Wed and Fri for 8 hours.
You are given 3 lists that indicate the dependency list among the tasks.
L1 = A->R->K->M (eg A can be completed if R is completed, R can be completed only if K is completed etc.)
L2 = N->G->V->E->Z->H
L3 = C->F->Y->D->J->P->T->S->W->B->C (cycle)
Each task needs one machine for its duration to complete.
Tasks cannot be resumed. Which means the 8 hour tasks cannot be executed over 2 days.
Each machine can process only one task at any time.
T1, T2 and T3 can process different tasks in parallel.
You are starting your schedule on a Wednesday.
Machines can be scheduled only during weekdays.
The first Monday in your schedule is a downtime for all the machines.
Given these constraints, write a program that generates a schedule between the tasks and machines such that all the tasks are completed at the
earliest.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm C++ Coding - 2of 2 votes
AnswersGiven a linked list: 5 -> 4 -> 3 -> 2 -> 1, produce the following output: 4 -> 2 -> 0 -> 2 -> 1 by substracting the 1st node with nth node, the 2nd with nth -1 node, etc... Only apply the stated action on the first half of the list
- NL May 11, 2014 in United States| Report Duplicate | Flag | PURGE
Software Engineer / Developer Coding - 0of 2 votes
AnswersWrite a program to count the number of numbers between two numbers a, b that have the sum of their bits equal to a fibonacci number.
- hulk May 11, 2014 in India
For example between 15 and 17 there are two numbers that have sum of bits equal to a fibonacci number.
15: 1111 sum=4
16: 10000 sum=1 (fibonacci)
17:10001 sum=2 (fibonacci)
So the output will be 2 in this case.
Test case -
Input 15 & 17
Input 173 & 10000003210005
The interviewer asked this to code in 5 hours in any programming language & mail him the full working program.| Report Duplicate | Flag | PURGE
Vdopia Software Engineer / Developer Coding - 6of 6 votes
AnswersGiven a array int a[]={2,5,1,9,3,7,2,8,9,3} and the no. of swap operations.We are allowed to do swap operations.
swap constraint: exchange only adjacent element.
Find the max number that can be formed using swap operations.
- koustav.adorable May 11, 2014 in Indiapublic static int[] maximize(int arr[],int swapsAllowed);
| Report Duplicate | Flag | PURGE
Amazon Web Developer Coding - 0of 0 votes
AnswerWrite a Programme for the Mine Sweeper Game in Java. Not necessary it should have any UI. this question was asked in Thoughtworks,Pune
- vsharma1985 May 07, 2014 in India for Java| Report Duplicate | Flag | PURGE
Coding - 3of 3 votes
Answerspublic class LogEntry {
- Invhelper May 05, 2014 in United States
public final long startTime; // start time of a job in millisec granularity
public final long endTime; // end time of a job in millisec granularity.
public final long ram; // the amount of ram the job occupies.
public final long jobId;
... constructor ...
}
running total of RAM
|
| 3GB
| -----
| 2GB
| ------
| 1GB -----------
|----- -----------
|
|____________________________________________________time
Find the peakRAM when the input is a collection of LogEntry objects| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 2 votes
AnswersGiven a string array ex: [1, 2, 3], find the permutation in best time.
- Invhelper May 05, 2014 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Coding - 0of 0 votes
AnswersGiven three strings a, b, c. Write a function to find the smallest subsequence in a, which contains all the characters from b but none from c.
- Green April 26, 2014 in India for Machine coding
* b and c are mutually exclusive.| Report Duplicate | Flag | PURGE
Flipkart Java Developer Coding - 0of 0 votes
AnswersCreate a Employee Database for an organization. Each employee may or may not have a manager. One employee may have many subordinates. This can grow upto any level.
- Green April 26, 2014 in India for Machine coding
* Find all the subordinates for a given employee.
* Find the manager details of an employee.
Assumptions:
* Employee contains
ID: int (Unique)
Name: string
Designation: string
Email: string
* One employee can have only one manager.
* All the information is in-memory. No database needed.| Report Duplicate | Flag | PURGE
Flipkart Java Developer Coding - 0of 0 votes
AnswersGiven a string of n characters how would you replace all occurrences of a particular character with some other character- with a time complexity less than O(n)?
- Pawan Kishor Singh April 23, 2014 in India
Note: W/o using any inbuilt string replace functions of the language.| Report Duplicate | Flag | PURGE
Adobe Coding - 2of 2 votes
Answersgive me the code for :
Given a string say "I am a human being" the output should reverse all letters of each word but not the whole string as such.
Eg: O/p should be "I ma a namuh gnieb"
I somewhat wrote the code, but i was asked what if there are extra spaces etc.
(i am able to write the code sitting at my desktop at one short but there front of interviewer i am struggling. Need to build up my confidence)
let me know the best and optimised way of writing this code.
Also i suggest people to aviod using inbuilt functions as much as possible
My Answer is as below in perl
- i_learn April 11, 2014 in India#i want the reverse of the letters of all words in a string #eg Input is "I am a human being" then o/p shud be "I ma a namuh gnieb" $str="I am a human being"; @arr=split(' ',$str); print @arr; for($i=@arr-1;$i>=0;$i--) { $_=@arr[$i]; ####intead of above for loop if we use foreach(@arr) then it will reverse the whole string @word=split('',$_); { foreach $n (@word) { unshift(@final,$n); } } } print "\n @final \n";
| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays Automata Coding Data Structures Dynamic Programming Perl - 0of 2 votes
AnswersGiven an array say [0,1,2,3,5,6,7,11,12,14,20]
- i_learn April 11, 2014 in India
given a number say 5.
Now find the sum of elements which sum to 5
eg:2+3=5, 0+5=5 etc.
I guess the interviewer wanted all possible combinations eg 0+2+3=5, etc| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays Coding Data Structures Dynamic Programming Perl Sorting test Testing - 0of 0 votes
AnswersGiven 2 strings str1 and str2. What is the efficient way to navigate from str1 to str2? The constraints are i) a string can be changed to another string by changing only one character. ii) all the intermediate strings must be present in dictionary. If not possible, return “not possible to navigate from str1 to str2″. (pre-processing is allowed and enough memory is available). for example: str1 = feel and str2 = pelt, then the navigation is feel -> fell -> felt -> pelt
- Rahul Sharma April 03, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - -1of 1 vote
AnswersSUM OF PREVIOUS SMALLER NUMBERS IN ARRAY efficiently. For every given element in the array you should return the sum of previous smaller values you encountered in the array . example : arr = {2, 5,1,9, 3}
- codechamp March 27, 2014 in United States
for a[0] i.e. 2 , sum = 0, a[1] i.e. 5, sum = 2, similarly for a[4], i.e. 3 , sum = 2+1 = 3.| Report Duplicate | Flag | PURGE
Zynga Software Engineer / Developer Coding