interview-questions

Compare two integer arrays with same length

[Description] Given two integer arrays with the same length. Design an algorithm which can judge whether they're the same. The definition of "same" is that, if these two arrays were in sorted order, the elements in corresponding position should be the same. [Example] <1 2 3 4> = <3 1 2 4> <1 2 3 4> != <3 4 1 1> [Limitation] The algo...

How to do run length encoding?

I have a long string for example it could be "aaaaaabbccc". Need to represent it as "a6b2c3". What's the best way to do this ? I could do this in linear time by comparing characters and incrementing counts and then replacing the counts in the array, using two indexes in one pass. Can you guys think of a better way than this? Are any of t...

What are the differences between value types and reference types in C#?

I know a few differences, Value types are stored on the stack where as reference types are stored on the managed heap. Value type variables directly contain their values where as reference variables holds only a reference to the location of the object that is created on the managed heap. Is there any other difference i missed... If s...

Management round of a Java/J2EE interview

What kind of topics/questions one can expect in a management round of an interview for a Java/J2EE sr.developer position. [EDIT] By management round I mean discussion with some one who is playing role of a project manager / technical manager. This round typically takes place after you are through with your coding tests and discussions w...

Find unique common element from 3 arrays

Original Problem: I have 3 boxes each containing 200 coins, given that there is only one person who has made calls from all of the three boxes and thus there is one coin in each box which has same fingerprints and rest of all coins have different fingerprints. You have to find the coin which contains same fingerprint from all of the 3 b...

tricky interview question for C++

Given the code below, how would you create/implement SR.h so that it produces the correct output WITHOUT any asterisks in your solution? I got bummed by this question. I would like to know some of the different approaches that people use for this problem. #include <cstdio> #include "SR.h" int main() { int j = 5; int a[] = {10,...

How many additional function calls does fib(n) require if "LINE 3" is removed?

I just got this question on an interview and had no idea how to calculate the answer. How many additional function calls does fib(n) require if "LINE 3" is removed? The answer should be in terms on n. int fib(int n) { if(n == 0) return 0; if(n == 1) return 1; if(n == 2) return 1; //LINE 3 HERE <--- return fib(n - 1) + fib(n - 2...

What really is a patch?

This was one of my interview questions which i couldn't answer.... Is it related to web developement? What really is a patch? and my interview question was how will u start new patch? ...

What is the purpose of Finalization in java?

Different websites are giving different opinions. My understanding is this: To clean up or reclaim the memory that an object occupies, the Garbage collector comes into action. (automatically is invoked???) The garbage collector then dereferences the object. Sometimes, there is no way for the garbage collector to access the object. The...

How do you write a deconstructor in Java?

I came across this question and am looking for some ideas? ...

Polymorphism and c#

Here one more basic question asked in MS interview recently class A { public virtual void Method1(){} public void Method2() { Method1(); } } class B:A { public override void Method1() { } } class main { A obk = new B(); obk.Method2(); } So which function gets called? Sorry for the typos. ...

Find maximum occuring integer (Mode) in an unsorted array

How to find the integer occurring maximum number of times (mode) in an unsorted array of integers? One O(nlogn) approach I could think of is to sort. Is there any other better approach? ...

Given a 2d array sorted in increasing order from left to right and top to bottom, what is the best way to search for a target number?

I was recently given this interview question and I'm curious what a good solution to it would be. Say I'm given a 2d array where all the numbers in the array are in increasing order from left to right and top to bottom. What is the best way to search and determine if a target number is in the array? Now, my first inc...

How to find smallest substring which contains all characters from a given string?

I have recently come across an interesting question on strings. Suppose you are given following: Input string1: "this is a test string" Input string2: "tist" Output string: "t stri" So, given above, how can I approach towards finding smallest substring of string1 that contains all the characters from string 2? ...

How to partition bits in a bit array with less than linear time

This is an interview question I faced recently. Given an array of 1 and 0, find a way to partition the bits in place so that 0's are grouped together, and 1's are grouped together. It does not matter whether 1's are ahead of 0's or 0's are ahead of 1's. An example input is 101010101, and output is either 111110000 or 000011111. Solv...

An interview question on conditional operator

I recently encountered with this question: How to reduce this expression: s>73?61:60;. The hint given was that Instead of using conditional operator we could use a simple comparison which will work fine. I am not sure but I think it is possible with some GCC extension,although I am unable to figure it out myself. EDIT:The whole expre...

How do you process a large data file with size such as 10G?

I found this open question online. How do you process a large data file with size such as 10G? This should be an interview question. Is there a systematic way to answer this type of question? ...

interview quesions book on C++. STL and boost

I w'd really appreciate if somebody suggest me any book which has good interview questions on C++, STL and boost? ...

How to find sum of elements from given index interval (i, j) in constant time?

Given an array. How can we find sum of elements in index interval (i, j) in constant time. You are allowed to use extra space. Example: A: 3 2 4 7 1 -2 8 0 -4 2 1 5 6 -1 length = 14 int getsum(int* arr, int i, int j, int len); // suppose int array "arr" is initialized here int sum = getsum(arr, 2, 5, 14); sum should be 1...

How to find 3rd max value of a column using MAX function in sql server?

Yesterday i had a question in an interview which i thought i could find answers here in SO... How to find 3rd max value of a column using MAX function in sql server? Consider the column to be Wages 20000 15000 10000 45000 50000 ...