Programming Interview Questions 21: Tree Reverse Level Order Print

This is very similar to the previous post level order print. We again print the tree in level order, but now starting from bottom level to the root. Using the same tree as before:

The output should be:
4 5 6
2 3
1
Continue reading

VN:F [1.9.22_1171]
Rating: 9.3/10 (19 votes cast)
Posted in Programming Interview | 12 Comments

Programming Interview Questions 20: Tree Level Order Print

Given a binary tree of integers, print it in level order. The output will contain space between the numbers in the same level, and new line between different levels. For example, if the tree is:

The output should be:
1
2 3
4 5 6
Continue reading

VN:F [1.9.22_1171]
Rating: 8.1/10 (20 votes cast)
Posted in Programming Interview | 13 Comments

Programming Interview Questions 19: Find Next Palindrome Number

Given a number, find the next smallest palindrome larger than the number. For example if the number is 125, next smallest palindrome is 131.

Continue reading

VN:F [1.9.22_1171]
Rating: 9.6/10 (70 votes cast)
Posted in Programming Interview | 25 Comments

Programming Interview Questions 18: Find Even Occurring Element

Given an integer array, one element occurs even number of times and all others have odd occurrences. Find the element with even occurrences.

Continue reading

VN:F [1.9.22_1171]
Rating: 8.6/10 (21 votes cast)
Posted in Programming Interview | 11 Comments

Programming Interview Questions 17: Search Unknown Length Array

Given a sorted array of unknown length and a number to search for, return the index of the number in the array. Accessing an element out of bounds throws exception. If the number occurs multiple times, return the index of any occurrence. If it isn’t present, return -1.

Continue reading

VN:F [1.9.22_1171]
Rating: 9.3/10 (43 votes cast)
Posted in Programming Interview | 9 Comments

Programming Interview Questions 16: Anagram Strings

Given two strings, check if they’re anagrams or not. Two strings are anagrams if they are written using the same exact letters, ignoring space, punctuation and capitalization. Each letter should have the same count in both strings. For example, ‘Eleven plus two’ and ‘Twelve plus one’ are meaningful anagrams of each other.

Continue reading

VN:F [1.9.22_1171]
Rating: 8.7/10 (20 votes cast)
Posted in Programming Interview | 28 Comments

Programming Interview Questions 15: First Non Repeated Character in String

One of the most common string interview questions: Find the first non-repeated (unique) character in a given string.

Continue reading

VN:F [1.9.22_1171]
Rating: 7.5/10 (15 votes cast)
Posted in Programming Interview | 18 Comments

Programming Interview Questions 14: Check Balanced Parentheses

Given a string of opening and closing parentheses, check whether it’s balanced. We have 3 types of parentheses: round brackets: (), square brackets: [], and curly brackets: {}. Assume that the string doesn’t contain any other character than these, no spaces words or numbers. Just to remind, balanced parentheses require every opening parenthesis to be closed in the reverse order opened. For example ‘([])’ is balanced but ‘([)]’ is not.

Continue reading

VN:F [1.9.22_1171]
Rating: 7.8/10 (54 votes cast)
Posted in Programming Interview | 11 Comments

Programming Interview Questions 13: Median of Integer Stream

Given a stream of unsorted integers, find the median element in sorted order at any given time. So, we will be receiving a continuous stream of numbers in some random order and we don’t know the stream length in advance. Write a function that finds the median of the already received numbers efficiently at any time. We will be asked to find the median multiple times. Just to recall, median is the middle element in an odd length sorted array, and in the even case it’s the average of the middle elements.

Continue reading

VN:F [1.9.22_1171]
Rating: 9.4/10 (72 votes cast)
Posted in Programming Interview | 36 Comments

Programming Interview Questions 12: Reverse Words in a String

This is probably by far the most common string manipulation interview question. Given an input string, reverse all the words. To clarify, input: “Interviews are awesome!” output: “awesome! are Interviews”. Consider all consecutive non-whitespace characters as individual words. If there are multiple spaces between words reduce them to a single white space. Also remove all leading and trailing whitespaces. So, the output for ”   CS degree”, “CS    degree”, “CS degree   “, or ”   CS   degree   ” are all the same: “degree CS”.

Continue reading

VN:F [1.9.22_1171]
Rating: 9.9/10 (21 votes cast)
Posted in Programming Interview | 21 Comments