## Software Engineer Interview Questions

- 0of 0 votes

AnswerWrite a function that compares Spanish strings, how would you handle special cases like 'ch' ?

- Gear November 17, 2016 in United States

c < ch < d, ch will be represented as 2 ASCII characters| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 3of 3 votes

AnswersDefine amazing number as: its value is less than or equal to its index. Given a circular array, find the starting position, such that the total number of amazing numbers in the array is maximized.

- wtcupup2017 November 13, 2016 in United States

Example 1: 0, 1, 2, 3

Ouptut: 0. When starting point at position 0, all the elements in the array are equal to its index. So all the numbers are amazing number.

Example 2: 1, 0 , 0

Output: 1. When starting point at position 1, the array becomes 0, 0, 1. All the elements are amazing number.

If there are multiple positions, return the smallest one.

should get a solution with time complexity less than O(N^2)| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 3of 3 votes

AnswersGiven 'n' circles (each defined by center and radius)

- sheva November 12, 2016 in United States

Write an algorithm to detect if circles intersect with any other circle in the same plane

Better than O(n^2) complexity| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersReturn the pivot index of the given array of numbers. The pivot index is the index where the sum of the numbers on the left is equal to the sum of the numbers on the right. Input Array {1,2,3,4,0,6}

- umesh.shaw November 11, 2016 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Arrays - 1of 1 vote

AnswersGiven the village of a map represented as a 2D grid containing houses,bushes and open-spaces, write a program to find a point for conducting a meeting in the map. Such point should be minimum from all the houses in the village.

Eg.`# # # # # # # A # # B # # # # # # # C # # # # # #`

# -> represents the bushes

- angry_scorpion November 10, 2016 in United States

A, B, C -> position of houses

I provided a O(n*a*b) approach, where n-> no. of houses , a,b->dimensions of the grid.

The interviewer asked me for some special cases. Can it be done more efficiently?| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersUsing that data structure, devise an algorithm to compute the dot product between two sparse matrices.

- Brookekelseyryan November 05, 2016 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswersWhat data structure would you use to store the entries of a sparse matrix?

- Brookekelseyryan November 05, 2016 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Data Structures - 1of 3 votes

AnswersCreate a function to calculate the height of an n-ary tree.

- theNightsKing16 November 03, 2016 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Trees and Graphs - 1of 1 vote

AnswersMagical binary strings are non-empty binary strings if the following two conditions are true:

- zandu November 01, 2016 in India

The number of 0's is equal to the number of 1's.

For every prefix of the binary string, the number of 1's should not be less than the number of 0's.

A magical string can contain multiple magical substrings. If two consecutive substrings are magical, then we can swap the substrings as long as the resulting string is still a magical string. Given a magical binary string, str, perform zero or more swap operations on its consecutive magical substrings such that the resulting string is aslexicographically large as possible. Two substrings are considered to be consecutive if the last character of the first substring occurs exactly one index before the first character of the second substring.

-----

Input Format

a single binary string, str.

Constraints

It is guaranteed that str is a binary string of 1's and 0's only.

1 ≤ length(str) ≤ 50

It is guaranteed that str is a magical string.

Output Format

Find a string denoting the lexicographically largest magical string that can be formed from str.

Sample Input 0

11011000

Sample output

11100100

Explanation of sample

Given the magical string str = 11011000, we can choose two consecutive magical substrings, 1100 and 10, to swap such that the resultant string, str' = 11100100, is the lexicographically largest possible magical string possible. Thus, we return the value of str', which is 11100100, as our answer.

.| Report Duplicate | Flag | PURGE

N/A Software Engineer Algorithm - 0of 0 votes

AnswersGiven a binary tree & the following TreeNode definition, return all root-to-leaf paths.

Definition of TreeNode:`public class TreeNode { public int val; public TreeNode left, right; public TreeNode(int val) { this.val = val; this.left = this.right = null; } }`

EXAMPLE

`Given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: [ "1->2->5", "1->3" ]`

From Lint Code - http://www.lintcode.com/en/problem/binary-tree-paths/

- johndifini October 29, 2016 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven a string, parse it and return a string array. It's like a tokenizer, but the rules are too...

- OctA October 29, 2016 in United States

For exmple, string="abc(edf)hij{klmn}opq[rst]uvw"

The delimiter are (), {}, []. They are in pair. So output array:

["abc", "edf", "hij", "klmn", "opq", "rst", "uvw"]

That's the rule 1. The rule 2 is, if any two consecutive "(" means escaping, that is "((" is actually output char "(". It's not part of the delimitor. Similar to ")", "{", "}", "[", "]".

abc(e))df) => ["abc", "e)df"], since the "))" outpus ")".

Rule 3: if "{" is inside a delimiter pair (), then "{" isn't part of the delimitor. Output it as is.

abc(e{df}}g) => ["abc", "e{df}}g"]| Report Duplicate | Flag | PURGE

HULU Software Engineer Algorithm - 1of 1 vote

Answers/*

- cheeyim October 28, 2016 in Singapore

# There's a room with a TV and people are coming in and out to watch it. The TV is on only when there's at least a person in the room.

# For each person that comes in, we record the start and end time. We want to know for how long the TV has been on. In other words:

# Given a list of arrays of time intervals, write a function that calculates the total amount of time covered by the intervals.

# For example:

# input = [(1,4), (2,3)]

# > 3

# input = [(4,6), (1,2)]

# > 3

# input = [(1,4), (6,8), (2,4), (7,9), (10, 15)]

# > 11

*/| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 2 votes

Answerswrite a SQL query to retrieve the number of students that received a GPA of 3 or 4. the query should return Total number of students that receive a GPA of 3 separate from Total number of students that receive GPA 4.

- aryan October 19, 2016 in United States

Schema:-

Student:- Student_ID, name, phoneno, email, gpa, gradyear

Classes: Class_ID, name, description

student_classes:- Class_ID, Student_ID, Grade| Report Duplicate | Flag | PURGE

Amazon Software Engineer Database - -1of 1 vote

AnswersGiven an un-directed weighted graph G(V,E), find the minimum weight between two given nodes X & Y

- gsharma34065 October 14, 2016 in India

(i.e. sum of weights of edges between X & Y).

You can add an extra egde with weight W between any two nodes in the graph exactly one time (if required).| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersGiven infinite supply of coins of denominations 25, 10, 5 and 1, find the distinct number of ways to use the coins to sum up to the given value

- rajansthapit October 10, 2016 in United States| Report Duplicate | Flag | PURGE

Adobe Software Engineer Algorithm - 0of 0 votes

AnswersGiven a string s, return all the palindromic permutations ( without duplicates), of it. Return an empty array if no palindromic combinations can be formed.

- NS October 04, 2016 in United States| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 0of 0 votes

AnswersGiven a string, determine if a permutation of a string can form a palindrome.

- NS October 04, 2016 in United States| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 0of 0 votes

AnswerYou have a web scraper that pulls car listing from Craiglist and other web sites. Design the system and API for the users to read the data.

- mrsurajpoudel.wordpress.com September 30, 2016 in United States

Follow-up : How will you scale your system?| Report Duplicate | Flag | PURGE

Triplebyte Software Engineer System Design - 0of 0 votes

AnswersDesign a cache for larger objects(>1MB) using memcached. You need to use API provided by memcached(which has constraint of not using more than 1MB of data per key). API are

- mrsurajpoudel.wordpress.com September 30, 2016 in United States`memcache.set(key, value) memcache.get(key)`

| Report Duplicate | Flag | PURGE

Triplebyte Software Engineer System Design - 0of 0 votes

AnswersWrite a program that reads a maze from a file and outputs from 'X' to 'O'. Example,

- mrsurajpoudel.wordpress.com September 30, 2016 in United States`Input: ########## X # # # # # # # # O ########## Output: ########## +++#+++++# # +#+ # +# # +++ # ++ ##########`

| Report Duplicate | Flag | PURGE

Software Engineer Algorithm - 3of 3 votes

AnswersFind the largest and smallest number in a list. The list is stored as two sections, one in ascending order and the other in descending order.

- uno September 29, 2016 in United States

input [ 2 3 4 5 6 7 10 9 8 7]

smallest : 2

Largest 10| Report Duplicate | Flag | PURGE

Google Software Engineer - 2of 2 votes

AnswersGiven an Array A with n elements. Pick maximum number of elements from given array following the rule:

- chan alex September 25, 2016 in United States

1. We cannot pick A[i] and A[j] if absolute value of (A[i] - A[j]) > absolute value of (i - j)

Example: {13,5,4}

Ans: 2

Pick 5 and 4.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 3of 3 votes

AnswersGiven: sorted array of integers

- 123georgedavid September 21, 2016 in United States

Return: sorted array of squares of those integers

Ex: [1,3,5] -> [1,9,25]

Integers can be negative.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - -1of 1 vote

AnswersYou have a bidimensional space of area N that contains a circle of area M that could be placed anywhere in this space. What is the optimal way of finding the circle, drawing lines, considering you have a function that can tell you if a line is intersecting the circle?

- Ray September 14, 2016 in United States| Report Duplicate | Flag | PURGE

Software Engineer Algorithm - 0of 2 votes

AnswersReturns the zero based index of the first occurrence of any character of str2 in str1

- tikolo September 06, 2016 in United States

Input:

str1="adf6ysh"

str2="123678"

output: 3

I have solved this by taking second string in hashset and then iterating first string one by one but i need more optimized way.| Report Duplicate | Flag | PURGE

Bloomberg LP Software Engineer Algorithm - 2of 2 votes

AnswersMr. Kim has to deliver refrigerators to N customers. From the office, he is going to visit all the customers and then return to his home. Each location of the office, his home, and the customers is given in the form of integer coordinates (x,y) (0≤x≤100, 0≤y≤100) . The distance between two arbitrary locations (x1, y1) and (x2, y2) is computed by |x1-x2| + |y1-y2|, where |x| denotes the absolute value of x; for instance, |3|=|-3|=3. The locations of the office, his home, and the customers are all distinct. You should plan an optimal way to visit all the N customers and return to his among all the possibilities.

- Loser September 03, 2016 in India

You are given the locations of the office, Mr. Kim’s home, and the customers; the number of the customers is in the range of 5 to 10. Write a program that, starting at the office, finds a (the) shortest path visiting all the customers and returning to his home. Your program only have to report the distance of a (the) shortest path.

You don’t have to solve this problem efficiently. You could find an answer by looking up all the possible ways. If you can look up all the possibilities well, you will get a perfect score.

[Constraints]

5≤N≤10. Each location (x,y) is in a bounded grid, 0≤x≤100, 0≤y≤100, and x, y are integers.

[Input]

You are given 10 test cases. Each test case consists of two lines; the first line has N, the number of the customers, and the following line enumerates the locations of the office, Mr. Kim’s home, and the customers in sequence. Each location consists of the coordinates (x,y), which is reprensented by ‘x y’.

[Output]

Output the 10 answers in 10 lines. Each line outputs the distance of a (the) shortest path. Each line looks like ‘#x answer’ where x is the index of a test case. ‘#x’ and ‘answer’ are separated by a space.

[I/O Example]

Input (20 lines in total. In the first test case, the locations of the office and the home are (0, 0) and (100, 100) respectively, and the locations of the customers are (70, 40), (30, 10), (10, 5), (90, 70), (50, 20).)

5 ← Starting test case #1

0 0 100 100 70 40 30 10 10 5 90 70 50 20

6 ← Starting test case #2

88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14

10 ← Starting test case #3

39 9 97 61 35 93 62 64 96 39 36 36 9 59 59 96 61 7 64 43 43 58 1 36

...

Output (10 lines in total)

#1 200

#2 304

#3 366| Report Duplicate | Flag | PURGE

Samsung Software Engineer Algorithm - 0of 0 votes

AnswersTime Complexity ?

- Ragesh September 02, 2016 in United States for Seattle

a. Inserting a node in Linked List?

b. HashMap time complexity?| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 0of 0 votes

AnswersFind missing number from sequence of numbers in an array? Time Complexity?

- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 0of 0 votes

AnswerTime Complexity ?

- Ragesh September 02, 2016 in United States for Seattle

a. Inserting a node in Linked List?

b. HashMap time complexity?| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm - 0of 0 votes

AnswersFind missing number from sequence of numbers in an array? Time Complexity?

- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE

Amazon Software Engineer Algorithm

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

Open Chat in New Window