## Software Engineer / Developer Interview Questions

- 0of 0 votes
Design an efficient hash function to perform 2D hashing.

Your function should be O(1) time and should minimize the probability of hash collisions as far as possible.

Basically, complete the following Java code ...`class TwoDData { private int x, y; public TwoDData(int x, int y) { this.x = x; this.y = y; } public int getX() { return this.x; } public int getY() { return this.y; } @Override public int hashCode() { // COMPLETE THIS METHOD } }`

- -1of 3 votes
Using GIT, how would you checkout a file, make changes and then commit the changes.

- 0of 2 votes
Given an array A of integers, having N elements.

It is desired to compute the sum of elements from index i to index j. This query is to be executed millions of times for any i, j values.

Give an O(1) implementation of this query.

You are allowed to do only one-time O(N) pre-processing.

- 0of 2 votes
Complete the following Java function

`boolean isValidIPv4Address(String input) { // true if "input" is a valid IPv4 address // false if not // Free to use any methods from these classes String/StringBuffer/StringBuilder only // Not allowed to use anything from java.net.* }`

- 0of 0 votes
The candidate had listed Chess as his hobby, and was asked the following question.

Design a data structure to represent the game of Chess.

Follow up : Write a function which returns true if enemy king is currently under Check, else returns false.

- 0of 2 votes
Give all testcases for the following function

`int binarySearch(int A[], int N, int dataToSearch) { // this function will return the index of "dataToSearch" if found, else -1 if not found. }`

- 0of 2 votes
Design a specialized stack which supports ALL of these operations in exactly O(1) time.

`class SpecializedStack { void push(int x) { // Adds an element to this stack in O(1) time } int pop() { // removes the topmost element in O(1) time } int getMax() { // gets the largest element of this stack in O(1) time } }`

- 0of 2 votes
Two words are called anagrams if one word can be formed by shuffling the letters of another word.

e.g. "hello" and "ollhe" are anagrams.

"listen" and "silent" are anagrams.

But, "cab" and "bag" are NOT anagrams.

Problem : Given a list of English words (all lowercase), write a function to "group" the anagrams together.

e.g. Input = {"abc", "def", "cab", "money", "bca", "yomen"}

Output =

{"abc", "cab", "bca"}

{"def"}

{"money", "yomen"}

Within each "group", the anagrams can occur in any sequence.

Also, sequence of groups is irrelevant.

Expected time complexity = O(NK^2), for N words with longest word length = K.

- 0of 0 votes
Detect if a given 2D matrix is a valid solution to a valid Sudoku puzzle or not.

Basically, you are given a (N^2) x (N^2) matrix where every cell has an integer value. Check if it is a valid Sudoku or not.

- 0of 0 votes
There are N number of houses in a straight line. House at index i has valuables worth V[i].

A thief is planning to rob as many houses as possible on this straight line.

Constraint : If he robs house at index i, then he cannot rob houses at indices (i - 1) and (i + 1).

Maximize the total value of valuables which he can rob.

- 0of 0 votes
What are two possible ways of passing by reference in C# language ?

Follow up : (Answer to above is "ref" and "out").

Which one would you use and why ?

- -1of 1 vote
Distinguish between final, finally and finalize keywords of Java language.

- -1of 1 vote
Give an O(N) time and O(1) memory function to check whether an array of integers is sorted in ascending order or not.

`public boolean isSortedArray(int[] A) { // complete this code ... }`

- 0of 0 votes
If you have 2 hotel rooms and 10 upcoming bookings. Such as

Booking 1. checkin Sept 1st to Sept 4

Booking 2. checkin Sept 9st to Sept 1

Booking 3. checkin Sept 1st to Sept 10

Booking 4. checkin Sept 11st to Sept 20

...

What should be the algorithm to optimize the room allocation?

When a new booking arrives in the future, how should the rooms to be re-allocated.

- 0of 0 votes
Write a logic to print the elements of 2D matrix in a spiral way?

for eg if int[][] matrix = {{1,2,3,4}{5.6,7,8}{9, 10, 11,12}};

The output should be 1 2 3 4 8 12 11 10 9 5 6 7

The interviewer asked me to implement a recursive algorithm.

- 1of 1 vote
Given a continuous stream of numbers, write a logic to find k maximum numbers at any given point of time where k is fixed?

- 0of 0 votes
Given some set of points in each quadrant of a 2D graph and two edges at a fixed angle, find the minimum angle at which the edges would cover maximum points between them?

I was confused on how to start and interviewer hinted me to consider each point at some angle from base (say 0) and continue finding all points which lies within the fixed angle.

- 0of 0 votes
How to design to record analytics for top n records that user listened in last 1 week? Please help.

- 0of 0 votes
How to design an image viewer app to see recent photos /albums from let's say Facebook? Please help

- 0of 0 votes
Implement multithreaded rm -r <folder>, i.e recursively delete files/folder under <folder> by walking through it and assume there can be billions of files under folder and you can only delete folder if all contents in it are first deleted

- 0of 0 votes
Implement Ring Buffer with read and write pointers.

For example if the Ring buffer is implemented in the form of array of integers , one should be able to read / write more than one integer at a time. In short the data read / written should be in a chunk .

- 0of 0 votes
Phone interview question from January.

We have a maze with three types of spaces:

1. Walls

2. Offices

3. Hallway space

Given a maze, determine which non-wall space would minimize the sum of all distances between that space and every office. You can only move up, down, left, and right.

(Edit: ChrisK described the problem more clearly than I did: "find the field that minimizes the sum of the shortest path[s] from this field to each office space.")

Example:`WWWWWWWW WWW O WW WWW OW WWW WWWW WO WWWW WWW WWWW WO W WWWWWWWW`

O = office, W = wall, spaces are hallway spaces

You can represent the maze however you want. That is, you can use any data structures you want, and you don't necessarily have to use O for office, W for Wall, and spaces for hallways.

(I'm not sure if you can actually start from an office space, but that should be a trivial issue because you can always just start a position adjacent to an office.)

- 0of 0 votes
Game of Death:

Implement an algorithm that produces the next move in the game of death.

Basically given a two dimensional array it will have either values 1 (live cell) or 0 (dead cell)

1. A Live cell will live only if it has two or three live neighbors All other cases die.

2. A dead cell with exactly three live neighbors will live otherwise no change, dead

Transform the array by using above two rules

- 0of 0 votes
Make 100 HTTP GET requests to http://en.wikipedia.org/wiki/Main_Page and print the following statistics for the response time to stdout:

• 10th, 50th, 90th, 95th, 99th Percentile

• Mean

• Standard Deviation

Your solution must be parallel. You must make at least N (say 10, but should be configurable). Use ExecutorService in Java for making the requests at a time.

Explain design choices, known limitations and edge cases.

What challenges did you face? How would you improve the code if you had more time?

- 0of 0 votes
Design an algorithm that provided your current location and a list of ATMs locations in the area, get you the closest K ATMs to your location.

Assume you have a method getDistance(a, b) that calculates the distance between a and b.

Follow Up:

Make your solution O(k) space and O(n) time

- 0of 0 votes
Design an algorithm to find the shortest substring in a synopsis such that it contains all the words in a provided list.

So, search for the shortest substring that contains ['Hello', 'World'].

- 0of 0 votes
Design a system for a parking lot where drivers can also have memberships (but also support guest drivers). The parking lot has counter screens on each row.

- 0of 0 votes
Design a message board system like Reddit were users can reply with messages on posted topics. How will you handle system scalability.

- 0of 0 votes
Regex matching algorithms

You will be given a string and a pattern string consisting of only '*','?', and small letters. You have to return tree or false based upon the comparisons.

? repersent one char.

* means zero or n number of char for any positive n.

Example

abc, a?c : true

abc, a*?c : true

abc, * : true

abc, ?c : false

- 0of 0 votes
You are given following design architecture.

`[DB] <==> [Server]`

Now let's say user are complaining about our server being slow, how would you figure out where is the problem?

2) now let's say the problem is in server, where do you think the problem is in server?

3) What if you found our server is fast, how about now?

4) you have also found that the network call from server to DB is also fast, how about now?

5) Lets say, our server is also setting near the complaining user, how about now?