## Software Engineer Interview Questions

- 0of 0 votes

AnswersDesign a train system which suggests shortest path and transfer needed to reach from source to destination. What can be the optimization.

- hm September 30, 2015 in United States

For example:

A system may have 10 trains from t1 to t10.

There are total 100 stops in the system s1 to s100.

Each train has fixed set of stops. You could allow to change and transfer train of source and destination does not cover using just 1 train.

What all can be APIs, data structure, optimizations scalable option.| Report Duplicate | Flag | PURGE

Software Engineer Algorithm Problem Solving Software Design System Design Trees and Graphs design - 8of 8 votes

AnswersGiven an array int32 arr[] of size n, return the number of non-empty contigious subarrays whose sum lies in range [a, b]

That is, implement the following naive algorithm faster than O(n^2)`def naive_algorithm(lst, a, b): result = 0 for i in xrange(len(lst)): for j in xrange(i, len(lst)): if a <= sum(lst[i:j + 1]) <= b: result += 1 return result`

Examples:

`count([1,2,3], 0, 3) = 3 # [1], [2], [3], [1, 2], [3] count([-2,5,-1], -2, 2) = 3 # [-2], [-1], [-2, 5, -1]`

You may assume that there are no overflows, that is sum(|x_i|) <= MAX_INT - 1

- emb September 26, 2015 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer - 0of 0 votes

AnswersWrite Program for String Permutations using most efficient algorithm. Can you solve problem in O(n) time ?

- dev123 September 23, 2015 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 1of 5 votes

AnswersYou are given an array of n unique integer numbers 0 <= x_i < 2 * n

- emb September 23, 2015 in United States

Print all integers 0 <= x < 2 * n that are not present in this array.

Example:

find_missing([0]) = [1]

find_missing([0, 2, 4]) = [1, 3, 5] # because all numbers are [0, 1, 2, 3, 4, 5]

find_missing([]) = []

find_missing([0, 1, 4, 5]) = [2, 3, 6, 7] # because all numbers are [0, 1, 2, 3, 4, 5, 6, 7]

Quirks are about requirements:

Time complexity O(n) - BUT there should be some fixed constant C independent of size of input such that every element of array is written/read < C times, so radix sorting the array is a no go.

Space complexity O(1) - you may modify the initial array, BUT sorted(initial_array) must equal sorted(array_after_executing_program) AND you can't store integers outside range [0, 2n) in this array (imagine that it's an array of uint32_t).| Report Duplicate | Flag | PURGE

Google Software Engineer Brain Teasers - 1of 1 vote

AnswersYou are given large numbers of logs, each one of which contains a start time (long), end time (long) and memory usage (int). The time is recorded as MMDDHH (100317 means October 3rd 5PM) Write an algorithm that returns a specific time (hour) when the memory usage is the highest. If there are multiple answers, return the first hour.

- aijackmoore September 21, 2015 in United States

e.g. 100207 100208 2

100305 100307 5

100207 100209 4

111515 121212 1

Answer: 100207

(Need to consider different scenarios like the time slots could be very sparse)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 4of 4 votes

AnswersWrite a program to process the matrix. If an element is 0 at ith row and jth column, then make the whole ith row and jth column to 0.

- codealtecdown September 17, 2015 in United States

Constraints:

Space complexity should be O(1)

Time complexity - Only single pass is allowed. Note that single pass is not O(n). This is single pass : An element will read and written only ones.

Edit:

Recursion is not allowed since it is O(n) space on stack| Report Duplicate | Flag | PURGE

Microsoft Software Engineer Algorithm - 2of 2 votes

AnswersGiven an array of task and k wait time for which a repeated task needs to wait k time to execute again. return overall unit time it will take to complete all the task.

- hm September 14, 2015 in United States

Example:

1. A B C D and k = 3

ans: 4 (execute order A B C D)

2. A B A D and k = 3

ans: 6 (execute order A B . . A D)

3. A A A A and k =3

ans: 13 (A . . . A . . . A . . . A)

4. A B C A C B D A and k = 4

ans: 11 (A B C . . A .C B D A )| Report Duplicate | Flag | PURGE

Twitter Software Engineer Algorithm - 6of 6 votes

AnswersPost order traversal for an N-ary tree iterative way.

- hm September 14, 2015 in United States

Given,

struct Node {

int val;

vector<Node*> children;

};

Without modifying original structure.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm C++ Trees and Graphs - 0of 0 votes

AnswersPost order traversal for an N-ary tree iterative way.

- hm September 14, 2015 in United States

Given,

struct Node {

int val;

vector<Node*> children;

};

To simplify you can modify the structure.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm C++ Trees and Graphs - 0of 0 votes

AnswersHow would you implement X-ray for Kindle? X-ray is an index of characters in a book that shows how often a character appears in the book, and at which places. I was explained how this index works, and what it will look like on the book. There re more details here: http://www.amazon.com/gp/help/customer/display.html?nodeId=200729910

- ravishchawla September 10, 2015 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm - 1of 1 vote

Answers. Given n strings consisting of ‘R’ and ‘B’. Two strings can be only combined if last character of first string and first character of second string are same. Given n strings, you have to output the maximum length possible by combining strings.

- ritwik_pandey September 09, 2015 in United States

I/P

RBR

BBR

RRR

output : 9| Report Duplicate | Flag | PURGE

Walmart Labs Software Engineer Algorithm - 2of 2 votes

AnswersThere's a very simple compression algorithm that takes subsequent characters and just emits how often they were seen.

- Phil September 08, 2015 in Netherland

Example:

abababaabbbaaaaa| Report Duplicate | Flag | PURGE

Booking.com Software Engineer Algorithm - 3of 3 votes

Answers`$a = [3, 1, 4, 5, 19, 6];`

`$b = [14, 9, 22, 36, 8, 0, 64, 25];`

# Some elements in the second array are squares.

- Phil September 08, 2015 in Netherland

# Print elements that have a square root existing in the first array.

# $b[1] = 9, it’s square root is 3 ($a[0])

# $b[3] = 36, it’s square root is 6 ($a[5])

# $b[7] = 25, it’s square root is 5 ($a[3])

# Result:

# 9

# 36

# 25| Report Duplicate | Flag | PURGE

Booking.com Software Engineer Algorithm - 2of 4 votes

AnswersYou are given a matrix n rows, m columns where each row is sorted in increasing order. Find median of the overall elements. What is the time complexity?

- emb September 07, 2015 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer - 1of 1 vote

AnswersYou are given a flat room 1x1 metres, a position of victim in it (v_x, v_y) and a position of a killer (k_x, k_y) both inside this room (in range [0, 1]).

- emb September 06, 2015 in United States

Then the killer shoots once at some direction. The bullet reflects of the walls as if it was a light ray - if it falls under angle X degrees, it will reflect at angle X degrees, if it gets into the corner it just reflects back. If the bullet hits guardian (see below) it stops and killer fails.

Write a function that will be given coordinates of victim and a killer and will return a list of coordinates of guardians such that it's impossible for a killer to kill victim.

That is, whichever direction the killer will shoot, the bullet will never reach victim, or will be stopped by a guardian.

Here is an example for the case when we assume the walls don't reflect bullet (for simplicity):

killer: (0, 0), victim: (1, 1). The solution to this simplified problem is to place 1 guardian between killer and victim e.g. on (0.1, 0.1).

Your task is to do this with accounting bullet reflection. E.g. in the previous case the killer can shoot at (1/3, 1), the bullet will reflect to (2/3, 0) and finally get to the victim at (1, 1).| Report Duplicate | Flag | PURGE

Google Software Engineer Brain Teasers - 0of 0 votes

AnswersImplement a method for the following signature:

`void * alignedAllocate(size_t sizeInBytes, size_t alignment) { }`

The method should allocate memory for the given size and the pointer should be aligned.

For example if`p = alignedAllocate(1000,64);`

p%8 should be 0.

- thewhatwhat September 05, 2015 in United States

Implement a second method that deleted the pointer give p.

Extend the delete method to handle multiple p's.| Report Duplicate | Flag | PURGE

Google Software Engineer C C++ - 0of 0 votes

AnswersGiven a 2-dimensional square matrix, rotate the matrix clockwise. Imagine concentric circles. Input from stdin: first line is length, subsequent lines are rows of the matrix. Output the matrix to stdout. This was one of the questions. You have 2 hrs to complete it.

- Yev September 02, 2015 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer Java - 0of 0 votes

AnswersGiven a positive integer, rearrange its digits to find the greatest positive integer. Expected time/space complexity O(1). I was to do this in space O(1), time O(n).

- Yev September 01, 2015 in United States| Report Duplicate | Flag | PURGE

OptionsCity Software Engineer Java - 1of 1 vote

AnswersWrite function to determine if given unsigned 32-bit number is a power of 3

`int is_power_of_3(uint32_t n)`

return 1 if yes, 0 otherwise.

e.g.`is_power_of_3(27) = 1 is_power_of_3(9) = 1 is_power_of_3(42) = 0 is_power_of_3(0) = 0`

Expected the answer not to be straightforward loop, but something faster.

- emb August 28, 2015 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Math & Computation - 1of 1 vote

AnswersGiven an array consisting of N Numbers.

- smarthbehl August 25, 2015 in United States

Divide it into two Equal(it is important) partitions (in size both contains N/2 elements) such that difference between sum of both partitions is minimum.

If number of elements are odd difference in partition size can be at most 1.| Report Duplicate | Flag | PURGE

Google Software Engineer - 1of 1 vote

AnswersWrite all solutions for a^3+b^3 = c^3 + d^3, where a, b, c, d lie between [0, 10^5] in at least O(n^2) complexity

- dev123 August 24, 2015 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - -2of 2 votes

AnswersA lovely place where ohm law is checked every day + you can feel the grapes (without the first letter).

- Pointer August 23, 2015 in United States for CMS

Clue:

** You can also find there gold… (The golden state)| Report Duplicate | Flag | PURGE

Micron Software Engineer Puzzle - 0of 0 votes

AnswersCan you think of a problem with the following singleton? If so, can you make it better and in the most efficient way?

- Pointer August 23, 2015 in United States for CMS

public class MySingelton {

private static volatile MySingelton mySingelton;

public static MySingelton getInstance() {

if (mySingelton == null) {

mySingelton = new MySingelton();

}

return mySingelton;

}

public static void main(String[] args) {

MySingelton s = MySingelton.getInstance();

...

}| Report Duplicate | Flag | PURGE

Micron Software Engineer Puzzle - 0of 0 votes

AnswersThe question inside the link.

- Pointer August 23, 2015 in United States for CMS

The pictures below contain a message in a secret code.

You will need to program to decode this message and to discover the password.

http://tsofen2015ms.azurewebsites.net/| Report Duplicate | Flag | PURGE

Micron Software Engineer Puzzle - 0of 0 votes

AnswersCompany will start a new marketing campaign targeting the users according

- JavaBuddy August 22, 2015 in United States

to their purchasing profiles.

This campaign has 3 kinds of messages each one targeting one group of customers:

Message 1 - targets the 25% of customers that spend most at the site

Message 2 - targets the 25% of customers that spend least at the site

Message 3 - targets the rest of the customers.

Given the list of purchases made during the week, write a program that lists

what kind of message each customer will receive.

Each purchase in this list features the customer id, the purchase amount among other information.| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm Java - 0of 0 votes

AnswerWrite a program to get out of the Maze. Maze can be represented in the form of Matrix where x can be represented as wall. and _ can be represented as a path.

- hm August 21, 2015 in United States| Report Duplicate | Flag | PURGE

EMC Software Engineer Algorithm - 1of 1 vote

AnswersDesign a data structure which should have following operation. Insert, Delete, Random access

- hm August 21, 2015 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Data Structures - 1of 1 vote

AnswersGiven 2 large number A and B, create a new number C using the digits from A which needs to be grater than B.

- hm August 21, 2015 in United States

e.g. A = 5281, B = 7443

C = 8125.| Report Duplicate | Flag | PURGE

Google Software Engineer Math & Computation - 0of 0 votes

AnswersDesign Twitter.

- SmashDUNK August 13, 2015 in United States| Report Duplicate | Flag | PURGE

Twitter Software Engineer design - 2of 2 votes

Answers

- chaos August 13, 2015 in United States for Windows`John observers the following while driving to work. • 4 were driving a red car. • 3 were driving a blue car. • 3 were driving a black car. He also notices that • 3 of them were listining to Hip Hop • 4 of them were listining to pop music. • 3 of them were listining to Rock. Additionally he notices that, • 3 of them reached office before time on Friday. • 3 of them reached office before time on Tuesday. • 2 of them reached office before time on Wednesday. • 2 of them reached office before time on Thursday. Which of the following practice maximises his chance of getting to office before time. a) He should drive a red car to work listining to pop music on a friday? b) He should drive a blue car to work listining to rock music on a Tuesday. State how did you calculate the probabiltiy for both in your answer.`

| Report Duplicate | Flag | PURGE

Microsoft Software Engineer Brain Teasers

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window