## Software Engineer / Developer Interview Questions

- 0of 0 votes
Given two sorted linked lists, how can you combine them into one big sorted list? Do not create additional nodes.

- 0of 0 votes
There is going to be a sale during this month. You are interested in a particular item and you found that different Vendors have different prices during different time periods. You collected the following information:

`Vendor => (start date, end date, price) both sides inclusive A => (1, 5, $20) B => (3, 6, $15) C => (2, 8, $25) D => (7, 12, $18) E => (1, 31, $22)`

As you can see, there are conflicting entries. You need to print out a non-conflicting schedule of prices, taking the best price from each period:

e.g.

(1, 2, $20), (3, 6, $15), (7, 12, $18), (13, 31, $22)

- 0of 0 votes
Given a list of currency exchange rates like this:

EUR/USD => 1.2

USD/GBP => 0.75

GBP/AUD => 1.7

AUD/JPY => 90

GBP/JPY => 150

JPY/INR => 0.6

write a method`double convert(String sourceCurrency, double amount, String destCurrency);`

For example, convert(EUR, 100, INR)

The method should minimize the number of intermediate conversions.

- 0of 0 votes
Given a grid of M*N size and robot is sitting on the top leftmost corner (0,0) and has to reach the bottom right most corner (M-1,N-1). Robot can only move up, down, left or right and cannot move diagonally. Find the shortest path on the grid.

Follow find total number of paths possible.

- 0of 0 votes
Write a function to convert a String of ip address to hex

eg: ip is 197.27.11.11 = 0xC51BBB

- 0of 0 votes
An web service maintains logs (suppose there are multiple log files per day) of all ip address which has requested service. If there is a DOS attack on the server find all ip addresses that has sent more number of requests and block them. Can this be done without writing any function in higher programming language?

What would the function look like if written in some language like C, Java etc?

Can this be done in Time optimized and space optimized manner?

- 0of 0 votes
What is the Big O of that algorithm? What happens at runtime?

- 0of 0 votes
What's the algorithm to transform the sentence "the brown fox ran fast" in "eht nworb xof nar tsaf" (reverse any word)

- 0of 0 votes
Write a merger and separator for Linked List.

eg: 1->2->3->4->5

separator()

1->3->5 and 2->4

merger()

1->2->3->4->5

- 1of 1 vote
Write a Java code that take a string of parenthesis as input and return if the string is valid or not . The input will have '(' and ')' and also '*' and * serves as wild card and can be used in place of both '(' and ')' or it can be null.

For example,the String (*)(*)(** is a valid String.

Follow up: What if '[]' and '{}' are also in the string along with '()' and * can be used in place of any of them or can be considered as null?

- 0of 0 votes
You are given a tree and any of the leaf node which is given as input is set to fire. And in each unit time all the neighbouring nodes of the nodes which are already in fire also catch fire. Given a tree find the time taken for the whole tree to catch fire.

The whole catches fire meaning all nodes catches fire.

Example :

4

/ \

5 6

/ \ / \

7 8 9 10

\ \

13 11

\

12

Assume the source leaf node : 9

At 1 sec : 6 catches fire

At 2 sec : 10 and 4 catches fire

At 3 sec : 5 catches fire

At 4 sec : 7 and 8 catches fire

At 5 sec : 13 and 11 catches fire

At 6 sec : 12 catches fire

If we have access to parent pointers its easy just BFS and keeping track of visited we get the answer.

How to go about the problem if we do not have access to parent pointers ??

- 0of 0 votes
All jumbled numbers of n digits in max (worst case) O(n) and min (avg case) O(log n) time.

A number is a jumbled number if the _absolute_ difference between adjacent digits is <=1.

For an input n=3

output should be

100

101

110

111

121

122

...

and so on.

The problem is similar to the one listed here https://www.careercup.com/question?id=5729332770111488

But this problem also has a O(n or log n) limitation and the solutions listed in the above mentioned problem at the time of posting this question, do not satisfy the criteria

PS: 001 is not a 3 digit number.

210 is absolutely fine as the absolute difference between adjacent digits is <=1.

- 0of 0 votes
Design a data structure that supports 3 below operations

1. GetNextId() : It returns the auto incremental next id. i.e 1 then 2 then 3 then 4

2. Acknolwdge(int i) : receives the acknowledgement of the id that was sent by GetNextId

3. GetIdLevel() : It returns the minimum id that has not been acknowledged

- 0of 0 votes
There is a primary machine and a secondary(backup machine). Write a program to sync files from primary to backup machine

- 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?