## Algorithm Interview Questions

- 0of 0 votes
How to Design an Meeting scheduler

- 0of 0 votes
How to randomly select a number in an array?

array: [15, 2, 4, 5, 1, -2, 0]

Follow-up:

Given a second array freq where freq[i] represents the occurrence of the ith number in array, how to randomly select a number in array based on the frequency.

Extra requirement:

Could you complete the selection in a single-pass(go through each array only once)?

- -2of 2 votes
In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.

Given a student's attendance record represented by a string with 3 possible characters 'L'(Late), 'A'(Absent), 'O' (On time),

check whether the student qualifies for the reward.

e.g.

@INPUT (String) "OLLAOOOLLO"

@RETURN (Boolean) False

The student does not qualify for reward because "LLA" means he was late for 3 times in a row.

@INPUT (String) "OLLOAOLLO"

@RETURN (Boolean) True

Follow-up:

If known the length of the attendance string is n, how many possible ways there is to attend school and make sure you get the reward.

- 0of 0 votes
In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.

Given a student's attendance record represented by a string with 3 possible characters 'L'(Late), 'A'(Absent), 'O' (On time), check whether the student qualifies for the reward.

e.g.

@INPUT (String) "OLLAOOOLLO"

@RETURN (Boolean) False

The student does not qualify for reward because "LLA" means he was late for 3 times in a row.

@INPUT (String) "OLLOAOLLO"

@RETURN (Boolean) True

Follow-up:

If known the length of the attendance string is n, how many possible ways there is to attend school and make sure the student gets the reward.

- 0of 0 votes
Find K which decides the number of open brackets are equal to the number of closed brackets.

input : (())

output : 2

Reason : if we divide the string at 2nd position, we get two open brackets and two closing brackets, and they are same .

input : (())))(

output : 4

Reason : if we divide the string(not necessarily equally) at 4rth position, we have (()) on the left side and on the right side we have ))( , as you can see, on the left half, we have two opening brackets and on the right half we have two closing brackets and they are equal .

input : ))

output : 2

Reason : there is no open brackets , so if we divide taking the whole string's length, we have )) on the left half and nothing on the right half. Now you can see that on the left half there is no open brackets and on the right half there is no closed brackets.

This question should be clear by now and remember you have to find out that K .

- 0of 0 votes
There are two integer array arrayA and arrayB in the same size and two integer countA and countB. If arrayA[i] > arrayB[i], then we increase countA by 1, if arrayB[i]>arrayA[i], then we increase countB by 1. We will do nothing otherwise. Now you are given arrayA and arrayB, write a function to shuffle arrayA and so you can get countA > countB. Assume the input array are always valid, not empty and the input is guaranteed to have answer.

For example:

arrayA = [12, 24, 8, 32]

arrayB = [13, 25, 32, 11]

After shuffle:

arrayA = [24, 32, 8, 12]

arrayB = [13, 25, 32, 11]

- 0of 0 votes
Find the Maximum number of distinct nodes in a binary tree path

- 0of 0 votes
Check if two given binary trees(expression trees with two characters 'a' and 'b' and obviously operators like +,-,*) are mathematically equivalent?

- 0of 0 votes
1) Given a file containing lines of chars, find if it contains "aaaaab\naaaaa" string pattern. Need to return true only if contains the EXACT pattern specified (observe the new line character).

2) How do you differentiate between actual new line and the new line character?

3) what if the file is way too big to bring it all in memory?

- 0of 0 votes
Top View of a Binary Tree in constant space

- 0of 0 votes
Given a pattern containing only Is and Ds. I for increasing and D for decreasing. Devise an algorithm to print the MINIMUM number following that pattern. Digits from 1-9 and digits can’t repeat.

Example:

1. Input: D Output: 21

2. Input: I Output: 12

3. Input: DD Output: 321

4. Input: II Output: 123

5. Input: DIDI Output: 21435

6. Input: IIDDD Output: 126543

7. Input: DDIDDIID Output: 321654798

- 0of 0 votes
Implement ConcurrentHashMap class in Java

- 0of 0 votes
Implement LinkedHashMap class in Java

- 0of 0 votes
You have been given a grid with some doors, walls and some empty spaces.

1st part : You have to tell the least no of moves to go from random position in the grid to the nearest door. You can move in four directions only, i.e, left, right, above, below.

2nd part : Least distance of every empty cell to the nearest door. Lots of discussion was done on both the parts of the problem.

- 0of 0 votes
Maximum triangle path Sum : Starting from the top of a pyramid of numbers like below, you can walk down going one step on the right or on the left, until you reach the bottom row:

55

94 48

95 30 96

77 71 26 67

One of such walks is 55 -> 94 >- 30 -> 26. You can compute the total of the numbers you have seen in such walk, in this case it’s 205.

Your problem is to find the maximum total among all possible paths from the top to the bottom row of the triangle. In the little example above it’s 321.

- -1of 1 vote
Design a system to upload images and tag them. Ability to search images with single and multiple tags.

- 0of 0 votes
Given a very large binary number which cannot be stored in a variable, determine the remainder of the decimal equivalent of the binary number when divided by 3. Generalize to find the remainder for any number k.

- 0of 0 votes
Given a file having many lines of text(words) and given a dictionary having an API function boolean isValid(String word), which will return true is a word passed to this function is valid word in dic.,and will return false if given passed argument is not a valid word in dic.

Now read the file and check if each word as well as all possible words from its L to R and R to L combinations, are valid words in dic. or not.

- 0of 0 votes
Given sequentially placed boxes, each representing a number( which may be positive or negative), we need to select the numbers in order to have the maximum sum, having the constraint that if we select a given box, we cannot select adjacent box to it, but can select any other.

- 0of 0 votes
Given 2 integers, add them without using any arithmetic operator

- 0of 0 votes
Implement a LRU cache with ttl at each block

- 0of 0 votes
Given some resources in the form of linked list you have to delete all the resources which sum up to 0(Zero) and return the remaining list.

- 0of 0 votes
Find all anagrams of a given string in a file of size 1TB.

- 0of 0 votes
Given two strings print all possible permutations of two strings such that the order of characters are maintained.

- 0of 0 votes
Given an array,generate all valid ip address from the array.

- 0of 0 votes
Find Longest Repeated Substring in the given string.

- 0of 0 votes
Given a equi-weighted uni directed graph and need to find the max distance possible from a given node.

- 0of 0 votes
Add 1 to the integer represented by a linked list with O(n) time, O(1) space, no recursion(stack space) and without reversing the linked list.

- 0of 0 votes
Write a program to check whether it is a valid binary tree or not.

- 0of 0 votes
Multiply two numbers represented as a linked list.