Programming, Software, and Technical Interview Questions

print all subsets of a multiset

Facebook 6 days ago 2 answers

for example aabcdddef is a multiset some subsets are: a aa ab aab aabc

print k-permutations of n distinct objects

Facebook 9 days ago 1 answer

the question in similar to printing k-subsets of n distinct objects.

Given an infinite stream of random integers, implement a function to choose one uniformly at random

Google about 1 month ago 1 answer

At any given time, any of the integers already seen in the stream should have equal probabilities of being chosen.

Write a function to return the intersection of a given number of sets of integers

Facebook 3 months ago 4 answers

public Set<Integer> findIntersection(List<Set<Integer>>) Explain the time and space complexity of your solution.

Given an infinite stream of numbers, write a function to find the N most frequently occurring numbers

LinkedIn 3 months ago

Your function should be able to take a stream of numbers and at any given point return the N most frequently occurring numbers in the stream.

Write functions to manipulate and traverse binary matrices

Facebook 3 months ago

Suppose you are given an integer matrix that can only contain ones and zeros. 1. Given a binary matrix, for every cell C that contains a zero set all other cells in C's row and column to zero as well. 2. Given a binary matrix, find the number of "clusters" of cell...

function which return union of two strings

Adobe 3 months ago 2 answers

Write a function that returns the union of two strings in C++.

Write a function to return the intersection of two integer arrays

Facebook 3 months ago 3 answers

Strive to be efficient and explain the runtime complexity of your algorithm. The signature looks something like this: int[] findIntersection(int[] a, int[] b)

How do you find the second largest element in a binary search tree?

LinkedIn 3 months ago

Note that you want to find the node with the *second* largest value.

Given a binary tree, print its elements level by level starting at the root node

LinkedIn 3 months ago 1 answer

The element should be printed such that lower levels (those closer to the root) are printed before higher levels. Within each level, nodes should be printed from left to right. For example, a tree like this: D / \ B E / \ ...

Given a binary tree, find the closest common ancestor for two tree nodes

Zynga 3 months ago

Your function should return the node that represents the closest common ancestor.

Given an integer array, find the maximum sum of consecutive elements

Google 4 months ago 2 answers

The sum should be the maximum possible number you can get by adding up consecutive integers in the array. For example, given an array -5 4 5 3 -1 -7 2 4 5 the maximum sum is `4 + 5 + 3 = 12`.

Write a function to find the height of a binary tree

Zynga 4 months ago

For a tree with a single root note, the height is 1.

Write a function to print all subsets of a certain size of the numbers from 0 to n

Facebook 4 months ago 2 answers

The function should print all the subsets of size `k` in any order. Signature: void printSubsets(int n, int k)

How would you design a class hierarchy and model to represent a deck of cards?

Zynga 5 months ago

Looking for the entities you would declare, their properties, and the relationships between the entities.

How would you implement a system for A/B testing?

Zynga 6 months ago

This was a higher level systems/design question.

N-ary tree. Find least common ancestor of 2 nodes in the Nary tree

Facebook 6 months ago 2 answers

Phone interview. write the function that returns least common ancestor of 2 nodes that may be present in a N-ary tree

What's the angle between the minute hand and the hour hand on a clock at a given time?

Zynga 6 months ago

Follow-up: In a 24 hour day, how often does the minute hand of a clock pass the hour hand?

Given a string representing DNA, return a list of strings each representing one of the proteins coded for by the DNA.

Facebook 6 months ago 1 answer

(Some details of DNA and protein are ignored here, you should ignore them too)

Given a n * m matrix print the elements of the matrix diagonally per line

eBay 7 months ago 3 answers

Example Input 4 9 11 3 18 6 22 0 7 5 8 13 Output 4 3 9 22 18 11 5 0 6 8 7 13

Linked list has even & odd elements in any order. Rearrange the linked list so that all odd elements are at start & all even to...

eBay 7 months ago 1 answer

Linked list ==> 9->8->6->13->11->4->7->4->9->100->NULL Output ==> 9->13->11->7->9->8->6->4->4->100->NULL

Given an unsorted array of integers, find a 3-element subset that sums to zero

Facebook 8 months ago 5 answers

Given an unsorted array of integers, find a 3-element subset that sums to zero. This is a special case of the SUBSET-SUM problem, which is NP-complete. Since we're only looking for subsets of 3 elements, this can be done in polynomial time.

Implement a function to balance parentheses in a string using the minimum number of edits

Facebook 10 months ago 5 answers

Write the function String balance(String input); that takes a string with parentheses and returns a modified string with balanced parentheses, using the minimum number of edits. For example, given the input string (pq(rs)t)u) the function should return...

Implement a function that rotates an array by a number of positions

Facebook 10 months ago 8 answers

Write the function int[] rotateArray(int[] input, int n); which rotates the `input` array by `n` positions. For example, the array [1, 2, 3, 4, 5, 6] rotated by 2 positions returns [5, 6, 1, 2, 3, 4]

Companies

Adobe Amazon.com AOL Apple Cisco eBay Electronic Arts Facebook Goldman Sachs Google Hewlett-Packard IBM Intel Intuit LinkedIn Microsoft Morgan Stanley NetApp Netflix Oracle Other Salesforce.com Twitter VMware Yahoo! Zynga