Top Software Developer Interview Questions

PROGRAMMING LANGUAGES
Java, C#, C/C++, Ruby
How does memory management work
Common collections or libraries

Q: How does memory management work in Objective-C?
With good target and confidence

Q: Write and aligned malloc() that gets memory size needed and an alignment mask as its arguments. Write a free() function to go with the aligned malloc that takes only the pointer to the allocated chunk of memory.
1. You basically need to allocated some extra memory with the memory segment that is requested so that you have enough space to align the said chunk and also save a pointer onto the original segment that you get from regular malloc. The free() method via some pointer math will get the “original pointer” and free it.
2. For malloc() you can use the concept of segregated list and do sbrk() to get that much chunk of memory from the kernel. It might lead to some internal fragmentation but thats fine…

Difference between Heap and Stack
3 Answers
I had no clue
all objects get stored in heap while all value type get stored in stack..heap automatically maage memory using garbage collection..while in stack explicitly memory is managed using destructors..in heap,CLR is responsile for memory management.
Heap : When you try to allocate memory by using “new ” keyword .The memory will be stored in heap memory. Stack : The memory will be allocated automatically and free automatically once variable out of the scope

Q: Difference between Memory leaks and memory management

Questions on prototype of dynamic memory management functions like malloc and free in C. Issues that can occur ( fragmentation , memory leak etc ). And use of static and auto variables in this context.




Facebook Interview Question for Software Engineers

Question 1: Binary tree to doubly linked list.

Question 2: Read 4 (Given the read4 API, read an entire file)

Question: System Design POI (Point of Interest. Given a point, find things within a radius).

Question 1: Decode way

Question 2: Random max index

Question: System design + component-wise design on download manager

All the algo questions were seen except the Random Max Index. Optimal solution is O(n) in time (single pass)and constant extra space.

Generate random max index
Given an array of integers, randomly return an index of the maximum value seen by far.

e.g.
Given [11,30,2,30,30,30,6,2,62, 62]

Having iterated up to the at element index 5 (where the last 30 is), randomly give an index among [1, 3, 4, 5] which are indices of 30 – the max value by far. Each index should have a ¼ chance to get picked.

Having iterated through the entire array, randomly give an index between 8 and 9 which are indices of the max value 62.

Solution:

public void sampleIdx(int[] array){
        if(array == null || array.length == 0){
            return;
        }
        Random rnd = new Random();
        int res = 0, max = Integer.MIN_VALUE, count = 0;
        for(int i = 0; i < array.length; i++){
            if(max < array[i]){
            	max = array[i];
                res = i;
                count = 1;
            }else if(max == array[i]){
                count++;
                int idx = rnd.nextInt(count); //(0, k - 1)
                if(idx == 0){

                    res = i;
		        System.out.print(“A max value index up to the ”+i +”th element is ” + res;
);

                }
            }
        }
    }

Algorithm Interview Questions
Page:1 2 3 4 5 6 7 8 9 10 »
Filter: Go Clear
Sort By: Date | Number of Comments | Most Recent Comment | Votes
facebook-interview-questions1
of 1 vote
1
Answer
Facebook Senior Engineer On-site 2017

1st Round
Question 1: Binary tree to doubly linked list.
Question 2: Read 4 (Given the read4 API, read an entire file)

2nd Round
Culture fit. No coding.

3rd Round
Question: System Design POI (Point of Interest. Given a point, find things within a radius).

Lunch
4th Round
Question 1: Decode way
Question 2: Random max index

5th Round
Question: System design + component-wise design on download manager

– aonecoding April 17, 2017 in United States | Report Duplicate | Flag
Facebook Software Engineer Algorithm
google-interview-questions2
of 2 votes
7
Answers
5th Round
Open-ended question What happens when you type a url in the browser and hit enter?

Second question Given an array of integers, print all the numbers that meet the following requirement – when the number is greater than every number on its left and smaller than every number on the right.

– aonecoding April 13, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
google-interview-questions0
of 2 votes
1
Answer
interviewed by senior engineer
Question Given two strings s1 and s2, combine the characters in the strings and maintain the sequence of characters
Follow-up If s1 has a length of m and s2 has a length of n, how many ways the strings could be merged. Figure out the formula F(m, n) = ?

– aonecoding April 13, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
google-interview-questions0
of 0 votes
3
Answers
Given a list of files. Return all the unique lines from all files.

– Ray April 12, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
amazon-interview-questions0
of 0 votes
4
Answers
You are given an unsorted binary array.
Ex [0 1 1 0 0 1 0 1 1 1 1 0 0 1 0 0 1]
and a number K, which represents the number of swap operations allowed on this binary array.
you need to find out the maximum length continuous subarray that can be generated using K many swaps.
Ex if K = 3 in above case
[0 1 1 0 0 1 0 1 1 1 1 0 0 1 0 0 1] => [0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1] => [0 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0] => [0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0]
so the answer is 9.

– sonesh April 10, 2017 in United States | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm
amazon-interview-questions0
of 0 votes
7
Answers
You are given a binary matrix whose each row is sorted. that means each row will have zeros at front and ones at the back. You need to find out the row which contains a maximum number of ones.
Ex :

[0 0 0 0 0 0 0 1 1 1 1 1]
[0 0 0 0 1 1 1 1 1 1 1 1]
[0 0 0 0 0 0 1 1 1 1 1 1]
[0 0 0 0 0 0 0 0 0 1 1 1]
[0 0 0 0 0 0 0 1 1 1 1 1]
[0 0 0 0 1 1 1 1 1 1 1 1]
Ans : second row and sixth with 8 ones. you will print [2,8] and [6,8];

Update : Required complexity O(M+N) + O(1) only.

– sonesh April 10, 2017 in United States | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm
google-interview-questions-2
of 2 votes
0
Answers
Find the coordinates of the rectangle which is parallel to axis and has minimum area.

– Ray April 08, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
google-interview-questions0
of 0 votes
3
Answers
Suppose you have a stream of (timestamp, tag) events. You need to filter this stream (online), leaving only events with tags that haven’t been already encountered in the last X seconds.

– Ray April 08, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
facebook-interview-questions0
of 0 votes
34
Answers
Given an array of integers:
1. rearrange the array such that all non-zero members appear on the left of the array (order is not important)
2. return the number of non-zero members

e.g. [1,2,0,5,3,0,4,0] => [1,2,5,3,4,0,0,0] and return 5. The non-zero array members can be in any order.

– xjohnwu April 07, 2017 in UK | Report Duplicate | Flag
Facebook Software Engineer / Developer Algorithm
bloomberg-lp-interview-questions1
of 1 vote
10
Answers
You are given an array of integers both negative and positive.
Print the maximum continuous sum of the array and if all the elements are negative, print the smallest of them.
Ex : [-20, -5, -2, -9] :> -2(-2)
Ex : [20, -19, 6, 9, 4] :-> 20(20)
Ex : [10, -3, 4, -2, -1, 10] -> 18 (10, -3, 4, -2, -1, 10)

Thanks velu007 for pointing out the mistake

– sonesh April 07, 2017 in United States | Report Duplicate | Flag
Bloomberg LP Software Engineer / Developer Algorithm
algorithm-interview-questions0
of 0 votes
1
Answer

– edboon06 April 06, 2017 in United States | Report Duplicate | Flag
Backend Developer Algorithm
amazon-interview-questions-1
of 3 votes
17
Answers
Find the frequency of a number in array in less than bigo n time
Array 1,2,2,3,4,5,5,5,2
Input 5
Output 3
Array 1,1,1,1,
Input 1
Output 4

Keep in mind less than bigo n

Thanks

– dinkar1708 April 01, 2017 in India | Report Duplicate | Flag
Amazon SDE-2 Algorithm Arrays
groupon-interview-questions0
of 0 votes
0
Answers
Delhi Route Traffic Optimizer

Traffic congestion is an annoying issue in Delhi, the capital of India. Every morning thousands of people drivea residential area to the International Technology Park (ITPL). There are various routes one can take to reach ITPL and each route takes its own time making some routes faster than the others. People obviously take faster routes which causes congestion on those roads too. Congestion results into increased travel time, air pollution and wastage of fuel. As a Traffic commissioner of Delhi, you are asked to optimize the traffic by putting toll to various roads so that resultant cost of every route (driving time cost and toll cost) ends up the same. This has to be done in such a way that any driver pays toll only once no matter which route he/she takes.roads have one-way traffic and there is no cycle in any of the routes. You need to create a toll plan for a given road layout.

The toll plan must adhere to following rules:

1. Toll should be levied in such a way that perceived cost (base road cost and toll cost) remains same forroads.
2. The tolls should be levied such that the total cost for each route is minimized.
3. A route cannot have more than one toll.
4. In case of multiple solutions for a route, add toll to a road that is closer to destination.
In some use cases, it might be impossible to impose tolls that satisfy the above conditions.

http://qa.geeksforgeeks.org/11340/delhi-route-traffic-optimizer

– raghunitb March 30, 2017 in India for Workflow | Report Duplicate | Flag
Groupon SDE1 Algorithm
facebook-interview-questions1
of 1 vote
11
Answers
Given some email ids, and a similarity function which says whether two email ids are similar, determine all the sets of email ids that are similar to each other.

– Ray March 28, 2017 in United States | Report Duplicate | Flag
Facebook Software Engineer Algorithm
facebook-interview-questions0
of 0 votes
12
Answers
You have a string consisting of open and closed parentheses, but parentheses may be imbalanced.
Make the parentheses balanced and return the new string.

– Ray March 26, 2017 in United States | Report Duplicate | Flag
Facebook Software Engineer Algorithm
bloomberg-lp-interview-questions1
of 1 vote
7
Answers
Given a list of URLs entered by a user write a program to print unique and most recently used URLs. For example if user entered the following: –
1. google.com
2. yahoo.com
3. wsj.com
4. google.com

The output should be :-
1. google.com
2. wsj.com
3.yahoo.com

– ik.yola March 25, 2017 in United States | Report Duplicate | Flag
Bloomberg LP Software Analyst Algorithm
adp-interview-questions0
of 0 votes
2
Answers
Given a movie X that the user had watched, write an algorithm to suggest more movies to the user. How to display the other movies based on same genre?

– suneel March 24, 2017 in India | Report Duplicate | Flag
ADP SDE-2 Algorithm
google-interview-questions2
of 2 votes
16
Answers
Given a sorted array, find all the numbers that occur more than n/4 times.

– alisonlee659 March 24, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
flipkart-interview-questions0
of 0 votes
1
Answer
How to Design an Meeting scheduler

– DuttaJ March 23, 2017 in India | Report Duplicate | Flag
Flipkart SDE-2 Algorithm
linkedin-interview-questions0
of 2 votes
7
Answers
How to randomly select a number in an array?
array: [15, 2, 4, 5, 1, -2, 0]

Follow-up:
Given a second array freq where freq[i] represents the occurrence of the ith number in array, how to randomly select a number in array based on the frequency.

Extra requirement:
Could you complete the selection in a single-pass(go through each array only once)?

– aonecoding March 22, 2017 in United States | Report Duplicate | Flag
Linkedin Software Engineer Algorithm
google-interview-questions1
of 5 votes
12
Answers
In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.
Given a student’s attendance record represented by a string with 3 possible characters ‘L'(Late), ‘A'(Absent), ‘O’ (On time),
check whether the student qualifies for the reward.

e.g.
@INPUT (String) “OLLAOOOLLO”
@RETURN (Boolean) False
The student does not qualify for reward because “LLA” means he was late for 3 times in a row.

@INPUT (String) “OLLOAOLLO”
@RETURN (Boolean) True

Follow-up:
If known the length of the attendance string is n, how many possible ways there is to attend school and make sure you get the reward.

– aonecoding March 22, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
google-interview-questions0
of 0 votes
0
Answers
In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.
Given a student’s attendance record represented by a string with 3 possible characters ‘L'(Late), ‘A'(Absent), ‘O’ (On time), check whether the student qualifies for the reward.

e.g.
@INPUT (String) “OLLAOOOLLO”
@RETURN (Boolean) False
The student does not qualify for reward because “LLA” means he was late for 3 times in a row.

@INPUT (String) “OLLOAOLLO”
@RETURN (Boolean) True

Follow-up:
If known the length of the attendance string is n, how many possible ways there is to attend school and make sure the student gets the reward.

– aonecoding March 22, 2017 in United States | Report Duplicate | Flag
Google Software Engineer Algorithm
amazon-interview-questions-1
of 1 vote
15
Answers
Find K which decides the number of open brackets are equal to the number of closed brackets.

input : (())
output : 2
Reason : if we divide the string at 2nd position, we get two open brackets and two closing brackets, and they are same .

input : (())))(
output : 4
Reason : if we divide the string(not necessarily equally) at 4rth position, we have (()) on the left side and on the right side we have ))( , as you can see, on the left half, we have two opening brackets and on the right half we have two closing brackets and they are equal .

input : ))
output : 2
Reason : there is no open brackets , so if we divide taking the whole string’s length, we have )) on the left half and nothing on the right half. Now you can see that on the left half there is no open brackets and on the right half there is no closed brackets.

This question should be clear by now and remember you have to find out that K .

– SmashDUNK March 21, 2017 in United States | Report Duplicate | Flag
Amazon SDE-2 Algorithm
microsoft-interview-questions0
of 0 votes
18
Answers
There are two integer array arrayA and arrayB in the same size and two integer countA and countB. If arrayA[i] > arrayB[i], then we increase countA by 1, if arrayB[i]>arrayA[i], then we increase countB by 1. We will do nothing otherwise. Now you are given arrayA and arrayB, write a function to shuffle arrayA and so you can get countA > countB. Assume the input array are always valid, not empty and the input is guaranteed to have answer.

For example:

arrayA = [12, 24, 8, 32]
arrayB = [13, 25, 32, 11]

After shuffle:

arrayA = [24, 32, 8, 12]
arrayB = [13, 25, 32, 11]

– gzyeli123 March 20, 2017 in United States | Report Duplicate | Flag
Microsoft SDE1 Algorithm
amazon-interview-questions0
of 0 votes
4
Answers
Find the Maximum number of distinct nodes in a binary tree path

– SmashDUNK March 20, 2017 in United States | Report Duplicate | Flag
Amazon SDE-2 Algorithm
google-interview-questions0
of 0 votes
8
Answers
Check if two given binary trees(expression trees with two characters ‘a’ and ‘b’ and obviously operators like +,-,*) are mathematically equivalent?

– SmashDUNK March 16, 2017 in United States | Report Duplicate | Flag
Google Software Engineer / Developer Algorithm
dropbox-interview-questions0
of 0 votes
0
Answers
1) Given a file containing lines of chars, find if it contains “aaaaab\naaaaa” string pattern. Need to return true only if contains the EXACT pattern specified (observe the new line character).

2) How do you differentiate between actual new line and the new line character?

3) what if the file is way too big to bring it all in memory?

– xankar March 10, 2017 in United States | Report Duplicate | Flag
Dropbox Backend Developer Algorithm
amazon-interview-questions0
of 0 votes
5
Answers
Top View of a Binary Tree in constant space

– neer.1304 March 10, 2017 in United States | Report Duplicate | Flag
Amazon SDE-3 Algorithm
amazon-interview-questions0
of 0 votes
19
Answers
Given a pattern containing only Is and Ds. I for increasing and D for decreasing. Devise an algorithm to print the MINIMUM number following that pattern. Digits from 1-9 and digits can’t repeat.

Example:
1. Input: D Output: 21
2. Input: I Output: 12
3. Input: DD Output: 321
4. Input: II Output: 123
5. Input: DIDI Output: 21435
6. Input: IIDDD Output: 126543
7. Input: DDIDDIID Output: 321654798

– neer.1304 March 10, 2017 in United States | Report Duplicate | Flag
Amazon SDE-3 Algorithm
amazon-interview-questions0
of 0 votes
0
Answers
Implement ConcurrentHashMap class in Java