## Software Engineer / Developer Interview Questions

- 0of 0 votes
Design Maps: You have set of [lat, long] for all famous locations. Given your position [lat, long] return all famous locations within r radius of your position.

- 0of 0 votes
You have set of [lat, long] of all famous locations. Given your position [lat, long] return all famous locations within radius r of your position

- 0of 0 votes
Given a number,print it in words.

19621 -> One lakh ninety six thousand and twenty one.

- 1of 1 vote
Given an array of type:-

1. Increasing

2. Decreasing.

3. Increase-Decrease

4. Decrease-Increase

Find:- 1. Type of array in minimum steps ?

2. Maximum element from array in min steps?

- 2of 2 votes
Question was "Given a pattern and a string input - find if the string follows the same pattern and return 0 or 1.

Examples:

1) Pattern : "abba", input: "redbluebluered" should return 1.

2) Pattern: "aaaa", input: "asdasdasdasd" should return 1.

3) Pattern: "aabb", input: "xyzabcxzyabc" should return 0.

I can think of a brute-force solution for this question where we add the character in the pattern and n length of the string to a hashmap and recurse over the pattern array and string. But is there anything more efficient? This was a pretty difficult question in my opinion.

- 1of 1 vote
You have 81 balls. 80 balls have the same weight. 1 ball is the lightest one. What would be the minimum possible way to find the lightest ball ?

(Use Dynamic Programming)

- 0of 0 votes
`There are multiple rooms in a floor. There are one or more fire exits. Each door can be designed with an option of pull or push. For fire safety, a door should be designed so as to open (push) towards the fire exit. Design a data structure to represent the floor and door design. A person could start from any room and moves towards fire exit. Write an algorithm to check if all the doors are designed to be pushed towards fire exit.`

- 1of 1 vote
There is a string whose characters can only be either ‘a’, ‘b’ or ‘_’ (there can be only one ‘_’ in the string). At each step, we can modify the string as follows:

1. ‘_’ can be swapped with its adjacent character, example “a_ba” can be changed to either “_aba” or “ab_a”.

2. Two characters adjacent to ‘_’ (both on the same side of ‘_’) can be reversed along with the ‘_’ if both characters are different, example, “aa_ba” can be changed to “aaab_” but not to “_aaba” because both characters are ‘a’.

You are given two strings, the initial state and the final state (lengths will be same), you have to output the minimum number of steps required to change the string in initial state to the string in the final state.

example:

input: a_b ab_

output: 1

input: abaa_a b_aaaa

output: 4

reason for example 2:- abaa_a -> aba_aa -> ab_aaa -> _baaaa -> b_aaaa

- 2of 2 votes
Write a program to find pattern.

0: 1

1: 11

2: 21

3: 1211

4: 111221

5: 312211

Iterate over the previous number, and find count for same number number. Append that count before number.

e.g.,

public String pattern(int input){}

If input = 4, function should return 111221.

- 2of 2 votes
Given a string S, you are allowed to convert it to a palindrome by adding 0 or more characters in front of it.

Find the length of the shortest palindrome that you can create from S by applying the above transformation.

- 2of 2 votes
Let's say there is a double square number X, which can be expressed as the sum of two perfect squares, for example, 10 is double square because 10 = 3^2 + 1^2

Determine the number of ways which it can be written as the sum of two squares

- 0of 0 votes
Write an algorithm that uses the divide and conquer technique. Given an array V with n int elements the algorithm should calculate the number of times that two consecutive 0's appear. Example :If V = [3, 0, 0, 1, 0, 1, 3, 2, 0, 0, 0, 1, 2], the algorithm should return 3, Note that 0, 0, 0 corresponds to having 2 pairs of consecutive zeros.

I was wondering if you guys can give me a step by step approach in solving these questions. I'm a recent grad and I want to know the best solutions to solve these problems. Thanks!

- 0of 0 votes
Sort the elements inside a stack using only push and pop opperation. Is it possible to do it only with one additional stack?

- 0of 0 votes
Build a function that takes one string and one regex expression in inputs and output true if the string matches the regex expression.

string: a-z

regex: a-z + * (where '*' matches 0 or more character and '+' matches one character)

- 0of 0 votes
t's laundry day, and, as usual, you've been putting this off for quite some time. Also, unfortunately, you lacked the foresight to actually ensure all your dirty laundry stayed in your hamper whilst it accumulated (what? we can't ALL be underwear basketball pros!).

Begrudgingly, you've gathered up all the clothing you could find and sent them through the wash. Now you have a disheveled pile of clean, albiet disorganized, accoutrements. You come to the realization that you probably lost some items in the fray, so now it's time to fold and figure out what's gone missing!

To get a good idea of the state of your wardrobe, count up the number of distinct shirts, pants, and underwear you have as you go through the laundry. Also pair up your socks, noting the number of pairs of each kind of sock and if there are any lonely souls (single (and ready to mingle) socks).

Input Specifications

Each article of clothing will have its own separate line. You have a penchant for hoarding, so there is no guarantee as to the number of pieces, but you can assure yourself that each article can be easily categorized by description (name).

Articles of clothing will be fed in as line-delimited list. See below for examples.

Output Specifications

Output should be an alphabetically (case-insensitive) sorted, line-delimited list of the articles of clothing along with their count. Each field (count, category) should be separated by a pipe (|). If you come across a sock without a soulmate, the count should be designated by a 0 (zero). Socks that are in pairs should be on separate lines from the socks of the same category without pairs, and should come before the pairless sock. See below for examples.

Sample Input/Output

INPUT

white shirt

polka dot sock

red sock

superhero shirt

torn jeans

polka dot sock

white shirt

polka dot sock

OUTPUT

1|polka dot sock

0|polka dot sock

0|red sock

1|superhero shirt

1|torn jeans

2|white shirt

EXPLANATION

As described above in the input and output specifications.

- 0of 0 votes
In gmail, while composing an email, upon adding a contact, related contacts are displayed. How would you implement that feature?

- Write an algorithm for that.

- What data structure would you use to store the weights?

- In what format would you persist this data?

- 1of 1 vote
We have words and there positions in a paragraph in sorted order. Write an algorithm to find the least distance for a given 3 words.

eg. for 3 words

job: 5, 9 , 17

in: 4, 13, 18

google: 8, 19, 21

...

...

Answer: 17, 18, 19

Can you extend it to "n" words?

Context: In Google search results, the search terms are highlighted in the short paragraph that shows up. We need to find the shortest sentence that has all the words if we have word positions as mentioned above.

- 0of 2 votes
write an algorithm to decide weather a string is a palindrome.

Ignore any non-letter characters in the the string.

Ignore capital/lower case.

Space complexity O(1)

for example, the following should return true:

A man, a plan, a canal -- Panama!

- 0of 0 votes
Given an arraylist of N integers,

(1) find a non-empty subset whose sum is a multiple of N.

(2) find a non-empty subset whose sum is a multiple of 2N.

Compare the solutions of the two questions.

- 1of 1 vote
Given a M * N matrix, if the element in thematrix is larger than other 8 elements who stay around it, then named thatelement be mountain point. Print all the mountain points.

- 0of 0 votes
In basket ball game for a player to win a game

challenge 1) 2 out of 3 throws should be basket

challenge 2) 4 out of 6 throws should be basket

which challenge should the player choose so that he might have better chance of winning the game?

- 0of 0 votes
In basket ball game for a player to win a game

challenge 1) 2 out of 3 throws should be basket

challenge 2) 5 out of 8 throws should be basket

which challenge should the player choose so that he might have better chance of winning the game?

- -2of 2 votes
Suppose we have array of N numbers. We will define N functions on this array. Each function will return the sum of all numbers in the array from Li to Ri ( Li is left index, Ri is right index). Now we have 2 types of queries:

Type1: 1 x y Change the xth element of the array to y

Type2: 2 l r Return the sum of all functions from m to n.

Input type:

First Line is the size of the array i.e. N

Next Line contains N space separated numbers Ai denoting the array

Next N line follows denoting Li and Ri for each functions.

Next Line contains an integer Q , number of queries to follow.

Next Q line follows , each line containing a query of Type 1 or Type 2

Here is an example:

Input:

5

1 2 3 4 5

1 2

3 4

1 4

1 5

3 5

5

1 1 5

2 2 4

2 1 3

1 4 5

2 1 5

Output:

40

28

63

Explanation:

Function 1 is sum of values from index 1 to index 2 = 1+2=3

So , F1=3

Similarly, F2=3+4=7

F3=1+2+3+4=10

F4=15

F5=12

Now when I query 1 1 5

means it is type 1 query, so we replace value at index 1 by 5.

So our new array is,

5 2 3 4 5

and

F1=7

F2=7(unchanged)

F3=14

F4=19

F5=12(unchanged)

Then next query is 2 2 4

means give sum of all functions from index 2 to 4.

So, ans= 7+14+19 =40 (output 1)

Similarly are other 2 outputs.

Index are 1 based in example.

Comment me if you are not clear with question.

Edit: I know one can do it with naive approach or using segment tree. But they wanted more faster way to do it.

- 0of 0 votes
Given a list of points, merge the intersecting points.

Example:

{-10,-5}{-1,5}{2,4}{5,10}{20,35}{12,17}{17,21}

Should output:

{-10,-5}{-1,10}{12,35}

Nothing falls between the {-10,-5} so this point stays. The {-1,5}{2,4} and {5,10} points can all be merged as they have intersecting points. They are merged to {-1,10}. The {20,35}{12,17} and {17,21} points can all be merged as they have intersecting points. They are merged to {12,35}

- -3of 3 votes
Goldman's conjecture - already posted,

Well ordered numbers - already posted.

- 0of 0 votes
The cows and bulls game, Player A chooses a word and player B guesses a word. You say bulls when a character in the player B's guess match with a character in player A's word and also it is in the corect position as in A's word. You say cows, when a character in the player B's word match the character in player A, but it is not in the correct position. The characters are case insensitive. Given two words player A's and player B's,Write a function that return the number of bulls and no of cows. For example,

A - Picture B- Epic, bulls -0, cows - 4

A - forum B - four, bulls - 3 cows - 1

- 0of 0 votes
Jumper Game: A NxN grid which contains either of 0-empty, 1 - player1, 2 - player 2. Given a position in the grid, find the longest jump path. For jump path, you can horizontally or vertically, you can jump on opponent cell and also the landing cell should be empty. No opponent cell can be jumped more than once. Write a function which takes grid and a specific position in the grid, and returns the longest possible number of jumps in the grid.

- -1of 1 vote
you are given an array or length 1million and rang of value from 0-m ... count the number of accurance of each number.

#2 the same array as above. find out the distance between min and max.

#3 write a malloc function.

and some theoretical Qs on routing Table.

There was one stupid guys who asked me given a binary tree and a depth of the tree print all the nodes in that tree on that depth.

when i used inserted a NULL node in my code he said it wont work as the value of NULL is 0 its not a pointer.... bla boa.... i was shocked that a guy who has code to take 3rd round of interview is saying these kind of thing :D..... there was one more thing that he said that in 'C' u cant declare a variable after the initial declaration in func tion body I said yes we should not but Now a days c compilers like gcc etc allows it ... god know he ever used gcc or not but he denied it 3 time..... really bad experience

- 0of 0 votes
Write a program to read file of following data structure: Name: favcolor=blue Find out which color is favorite by most people (print the color and number of people)

- 0of 0 votes
You have a binary tree where each node knows the number of nodes in its sub-tree (including itself).

Given a node n and an int k,

write a function to return the kth

node in an in order traversal.

Can you do this non recursively